Skip to content

Commit

Permalink
apacheGH-2787: Set flag before causing class initializations
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Oct 27, 2024
1 parent 04f377d commit 6253069
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 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,22 @@ 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.
// Overlapping attempts to perform initialization will block on the synchronized
// but threads may have already have initialization locks.
synchronized(JenaSystem.class) {
if ( initialized )
return ;
// Set the flag before, before setup() takes any initialization locks
// that may deadlock with another thread.
// See https://github.com/apache/jena/issues/2787
initialized = true;
setup();
if ( DEBUG_INIT )
singleton.debug(DEBUG_INIT);
singleton.initialize();
singleton.debug(false);
// Last so overlapping initialization waits on the synchronized
initialized = true;
}
}

Expand Down

0 comments on commit 6253069

Please sign in to comment.