Skip to content

Commit

Permalink
Fix eager classes
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Apr 23, 2024
1 parent 4e344aa commit 9b6ac0f
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

Expand Down Expand Up @@ -80,6 +82,42 @@ public StartupActionImpl(CuratedApplication curatedApplication, BuildResult buil
resources, transformedClasses);
}
this.runtimeClassLoader = runtimeClassLoader;
handleEagerClasses(runtimeClassLoader, eagerClasses);
}


private void handleEagerClasses(QuarkusClassLoader runtimeClassLoader, Set<String> eagerClasses) {
int availableProcessors = Runtime.getRuntime().availableProcessors();
if (availableProcessors == 1) {
return;
}
//leave one processor for the main startup thread
ExecutorService loadingExecutor = Executors.newFixedThreadPool(availableProcessors - 1);
for (String i : eagerClasses) {
loadingExecutor.submit(new Runnable() {
@Override
public void run() {
try {
//no need to restore the old TCCL, this thread is going away
Thread.currentThread().setContextClassLoader(runtimeClassLoader);
runtimeClassLoader.loadClass(i);
} catch (ClassNotFoundException e) {
log.debug("Failed to eagerly load class", e);
//we just ignore this for now, the problem
//will be reported for real in the startup sequence
}
}
});
}
Thread t = new Thread(new Runnable() {
@Override
public void run() {
//when all the jobs are done we shut down
//we do this in a new thread to allow the main thread to continue doing startup
loadingExecutor.shutdown();
}
});
t.start();
}

/**
Expand Down

0 comments on commit 9b6ac0f

Please sign in to comment.