Skip to content

Commit 14125e0

Browse files
committed
Make singleton implementation thread-safe
1 parent c7fe851 commit 14125e0

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/symbols/internal/SymbolIconProviderRegistry.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public class SymbolIconProviderRegistry {
3636

3737
private static final String EXTENSION_POINT_ID = LanguageServerPlugin.PLUGIN_ID + ".symbolIconsProvider"; //$NON-NLS-1$
3838

39-
private static SymbolIconProviderRegistry INSTANCE = null;
40-
4139
// default icon provider from LSP4E
4240
private final SymbolIconProvider defaultIconProvider = new SymbolIconProvider();
4341

@@ -48,11 +46,17 @@ private SymbolIconProviderRegistry() {
4846
loadExtensions();
4947
}
5048

49+
/**
50+
* Initialization-on-demand holder: the JVM guarantees that this nested class
51+
* is loaded and initialized exactly once, in a thread-safe manner, the first
52+
* time {@link #get()} is called.
53+
*/
54+
private static final class Holder {
55+
static final SymbolIconProviderRegistry INSTANCE = new SymbolIconProviderRegistry();
56+
}
57+
5158
private static SymbolIconProviderRegistry get() {
52-
if (INSTANCE == null) {
53-
INSTANCE = new SymbolIconProviderRegistry();
54-
}
55-
return INSTANCE;
59+
return Holder.INSTANCE;
5660
}
5761

5862
private void loadExtensions() {

0 commit comments

Comments
 (0)