arne-bdt commented on issue #2787:
URL: https://github.com/apache/jena/issues/2787#issuecomment-2436229951

   > Is the `LazyHolder` approach any different from the 5.1.0 approach in 
`SystemJena.init`? A second thread coming in is not waiting for initialization 
to complete and may access classes in a different order. (We don't have a 
reproducible example.)
   
   The `LazyHolder` replaces the `synchronized(JenaSystem.class)` block. Unlike 
the synchronized block, the JVM ensures that the `LazyHolder` is only accessed 
once, so there’s no need for double-checking with `if (initialized) return;`. 
This makes it both highly efficient and more robust.
   
   When running `org.apache.jena.sys.TestJenaSystem#testFirstInitParallel` 
directly from the IDE (without prior initialization of `JenaSystem`), it’s 
quite straightforward to observe the exact behavior, and the test consistently 
produces reliable results. So far, I haven’t encountered any non-reproducible 
behavior (e.g., due to timing issues). 
   Which kind of reprodicible example are you missing?
   
   However, I have not yet figured out how to integrate this test to run it 
with Maven in a separate JVM instance to ensure that the `JenaSystem` has not 
been initialised.
   
   For more information on the pattern, you can refer to the documentation 
[here](https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom) and 
[here](https://dzone.com/articles/another-singleton-implementation#:~:text=%7D-,Lazy%20Initialization%20Holder%20Class%20Idiom,in%20an%20inner%20class%20SingletonHolder.).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to