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 80073b2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,23 @@ public static void logLifecycle(String fmt, Object ...args) {
}

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 ;
// Access the initialized flag to trigger class loading
var unused = LazyInitializer.IS_INITIALIZED;
}

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;
}
}

Expand Down

0 comments on commit 80073b2

Please sign in to comment.