This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new 0f9ff7dbe0 GH-2787: Use lazy holder pattern for system initialization
0f9ff7dbe0 is described below
commit 0f9ff7dbe0bea67966a79c2b89734b77703db5ea
Author: Andy Seaborne <[email protected]>
AuthorDate: Tue Oct 29 11:10:09 2024 +0000
GH-2787: Use lazy holder pattern for system initialization
---
.../src/main/java/org/apache/jena/sys/JenaSystem.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
b/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
index 09871f83b9..5602bcbf56 100644
--- a/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
+++ b/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
@@ -77,20 +77,23 @@ public class JenaSystem {
}
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;
}
}