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

   > 
   > (Because this is critical in Jena, forgive me for wanting to get into the 
details.)
   > 
   > I don't quite understand "more robust" here. The second thread is allowed 
to continue once initialized is set true. LazyHolder is (I don't have a 
solution for that and it may be a non-issue because the second thread bumps 
into an initializing class.)
    
   @afs This pattern is a "cleaner" approach to static initialization, as it 
delegates synchronization responsibility to the JVM. t also guarantees the code 
executes only once. To replicate what the JVM does for us, we currently use 
`synchronized `and a secondary check within the synchronized block for any 
thread that reaches that point and is waiting:
   ```java
   synchronized(JenaSystem.class) {
               if ( initialized )
                   return ;
               ...
   }
   ```
   
   I understand that introducing this pattern may have caused some confusion, 
as it does not directly contribute to solving the problem. The actual fix was 
simply moving `initialized = true;` back to its original position.
   
   Since I prefer to clean up code whenever I need to modify it, I introduced 
the pattern. We are early in the Jena 5.3 cycle, and we have code to reproduce 
the threading issues along with solid tests. I ran numerous test iterations 
that demonstrated stable behavior. 
   Given this, I valued the benefits of the initialization pattern over the 
potential risk of a different runtime behavior.


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