arne-bdt commented on issue #2787:
URL: https://github.com/apache/jena/issues/2787#issuecomment-2431661976
In an attempt to make the possible blockage and cause visible to the user, I
may have inadvertently fixed it:
```java
private static volatile boolean initialized = false ;
private static Semaphore initializationSemaphore = new Semaphore(1);
private static ThreadLocal<Boolean> isInitializing =
ThreadLocal.withInitial(() -> false);
public static void init() {
// Once jena is initialized, all calls are an immediate return.
if ( initialized )
return ;
// if the same thread is calling init(), while the initialization is in
progress, return immediately
if(isInitializing.get())
return ;
isInitializing.set(true); // set the flag to true to indicate that the
initialization is in progress
try {
// Only one thread can initialize Jena.
if(initializationSemaphore.tryAcquire(5, TimeUnit.SECONDS)) {
if ( initialized )
return ;
setup();
if ( DEBUG_INIT )
singleton.debug(DEBUG_INIT);
singleton.initialize();
singleton.debug(false);
// Last so overlapping initialization waits on the synchronized
initialized = true;
}
} catch (InterruptedException e) {
throw new RuntimeException("Timeout while waiting for semaphore to
initialize JenaSystem. Please call JenaSystem.init() before working with
multiple threads.", e);
} finally {
initializationSemaphore.release();
isInitializing.remove();
}
}
```
--
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]