Skip to content

Commit

Permalink
save virtual threads to replace a not closed yet jar file ref
Browse files Browse the repository at this point in the history
(cherry picked from commit bd1fe70)
  • Loading branch information
franz1981 authored and gsmet committed Sep 13, 2024
1 parent 1413f3e commit 7133446
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ static <T> T withJarFile(JarResource jarResource, String resource, JarFileConsum

// Happy path: the jar reference already exists and it's ready to be used
final var localJarFileRefFuture = jarResource.jarFileReference.get();
boolean closingLocalJarFileRef = false;
if (localJarFileRefFuture != null && localJarFileRefFuture.isDone()) {
JarFileReference jarFileReference = localJarFileRefFuture.join();
if (jarFileReference.acquire()) {
return consumeSharedJarFile(jarFileReference, jarResource, resource, fileConsumer);
}
closingLocalJarFileRef = true;
}

// There's no valid jar reference, so load a new one
Expand All @@ -160,7 +162,7 @@ static <T> T withJarFile(JarResource jarResource, String resource, JarFileConsum
final var newJarFileRef = syncLoadAcquiredJarFile(jarResource);
// We can help an in progress close to get rid of the previous jarFileReference, because
// JarFileReference::silentCloseJarResources verify first if this hasn't changed in the meantime
if (jarResource.jarFileReference.compareAndSet(localJarFileRefFuture, newJarFileRef) ||
if ((closingLocalJarFileRef && jarResource.jarFileReference.compareAndSet(localJarFileRefFuture, newJarFileRef)) ||
jarResource.jarFileReference.compareAndSet(null, newJarFileRef)) {
// The new file reference has been successfully published and can be used by the current and other threads
// The join() cannot be blocking here since the CompletableFuture has been created already completed
Expand Down

0 comments on commit 7133446

Please sign in to comment.