Skip to content

Commit

Permalink
apacheGH-2787: Use lazy holder pattern for system initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Oct 29, 2024
1 parent f9e5778 commit 947ef39
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,27 @@ public static void logLifecycle(String fmt, Object ...args) {
System.err.println() ;
}

public static void init() {
// Once jena is initialized, all calls are an immediate return.
if ( initialized )
return ;
// Overlapping attempts to perform initialization will block on the synchronized.
synchronized(JenaSystem.class) {
if ( initialized )
return ;
private static class LazyInitializer {
static final boolean IS_INITIALIZED = jenaSystemInitialization();

private static boolean jenaSystemInitialization() {
JenaSystem.initialized = true; // Set early to avoid blocking on static initialization.
setup();
if ( DEBUG_INIT )
singleton.debug(DEBUG_INIT);
singleton.initialize();
singleton.debug(false);
// Last so overlapping initialization waits on the synchronized
initialized = true;
return true;
}
}

public static void init() {
if ( initialized )
return ;
// Access the initialized flag to trigger class loading
var unused = LazyInitializer.IS_INITIALIZED;
}

public static void shutdown() { singleton.shutdown(); }

/** The level 0 subsystem - inserted without using the Registry load function.
Expand Down

0 comments on commit 947ef39

Please sign in to comment.