Skip to content

Commit

Permalink
Revert "More aggressively reset thread context classloaders on test/d…
Browse files Browse the repository at this point in the history
…evmode restart"

This reverts commit a10b327.
  • Loading branch information
yrodiere committed Oct 30, 2023
1 parent 27a25e5 commit 9db95f1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import org.jboss.logging.Logger;

import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.runtime.util.ThreadUtil;

public class ForkJoinClassLoading {

private static final Logger log = Logger.getLogger(ForkJoinClassLoading.class.getName());
Expand All @@ -21,20 +18,15 @@ public class ForkJoinClassLoading {
* than nothing.
*
* Really we should just not use the common pool at all.
*
* @param classLoader The classloader to use as the new Context ClassLoader for ForkJoinPool threads.
* @param mode The bootstrap mode of the application being booted / shut down.
*/
public static void resetClassLoaderReferences(ClassLoader classLoader, QuarkusBootstrap.Mode mode) {
boolean aggressive = mode != QuarkusBootstrap.Mode.PROD;

public static void setForkJoinClassLoader(ClassLoader classLoader) {
CountDownLatch allDone = new CountDownLatch(ForkJoinPool.getCommonPoolParallelism());
CountDownLatch taskRelease = new CountDownLatch(1);
for (int i = 0; i < ForkJoinPool.getCommonPoolParallelism(); ++i) {
ForkJoinPool.commonPool().execute(new Runnable() {
@Override
public void run() {
ThreadUtil.resetClassLoaderReferences(Thread.currentThread(), classLoader, aggressive);
Thread.currentThread().setContextClassLoader(classLoader);
allDone.countDown();
try {
taskRelease.await();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public StartupActionImpl(CuratedApplication curatedApplication, BuildResult buil
* of the JVM will exit when the app stops.
*/
public RunningQuarkusApplication runMainClass(String... args) throws Exception {

//first we hack around class loading in the fork join pool
ForkJoinClassLoading.resetClassLoaderReferences(runtimeClassLoader,
curatedApplication.getQuarkusBootstrap().getMode());
ForkJoinClassLoading.setForkJoinClassLoader(runtimeClassLoader);

//this clears any old state, and gets ready to start again
ApplicationStateNotification.reset();
Expand Down Expand Up @@ -175,8 +175,7 @@ private void doClose() {
| ClassNotFoundException e) {
log.error("Failed to stop Quarkus", e);
} finally {
ForkJoinClassLoading.resetClassLoaderReferences(runtimeClassLoader,
curatedApplication.getQuarkusBootstrap().getMode());
ForkJoinClassLoading.setForkJoinClassLoader(ClassLoader.getSystemClassLoader());
if (curatedApplication.getQuarkusBootstrap().getMode() == QuarkusBootstrap.Mode.TEST) {
//for tests, we just always shut down the curated application, as it is only used once
//dev mode might be about to restart, so we leave it
Expand All @@ -188,8 +187,7 @@ private void doClose() {
@Override
public int runMainClassBlocking(String... args) throws Exception {
//first we hack around class loading in the fork join pool
ForkJoinClassLoading.resetClassLoaderReferences(runtimeClassLoader,
curatedApplication.getQuarkusBootstrap().getMode());
ForkJoinClassLoading.setForkJoinClassLoader(runtimeClassLoader);

//we have our class loaders
ClassLoader old = Thread.currentThread().getContextClassLoader();
Expand Down Expand Up @@ -258,8 +256,7 @@ public void overrideConfig(Map<String, String> config) {
*/
public RunningQuarkusApplication run(String... args) throws Exception {
//first we hack around class loading in the fork join pool
ForkJoinClassLoading.resetClassLoaderReferences(runtimeClassLoader,
curatedApplication.getQuarkusBootstrap().getMode());
ForkJoinClassLoading.setForkJoinClassLoader(runtimeClassLoader);

//we have our class loaders
ClassLoader old = Thread.currentThread().getContextClassLoader();
Expand Down Expand Up @@ -302,8 +299,7 @@ public void close() throws IOException {
runtimeClassLoader.close();
}
} finally {
ForkJoinClassLoading.resetClassLoaderReferences(runtimeClassLoader,
curatedApplication.getQuarkusBootstrap().getMode());
ForkJoinClassLoading.setForkJoinClassLoader(ClassLoader.getSystemClassLoader());

for (var i : runtimeApplicationShutdownBuildItems) {
try {
Expand Down
56 changes: 0 additions & 56 deletions core/runtime/src/main/java/io/quarkus/runtime/util/ThreadUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.ThreadPoolConfig;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.util.ThreadUtil;
import io.quarkus.vertx.core.runtime.config.AddressResolverConfiguration;
import io.quarkus.vertx.core.runtime.config.ClusterConfiguration;
import io.quarkus.vertx.core.runtime.config.EventBusConfiguration;
Expand Down Expand Up @@ -158,7 +157,7 @@ private void tryCleanTccl() {
synchronized (devModeThreads) {
currentDevModeNewThreadCreationClassLoader = cl;
for (var t : devModeThreads) {
ThreadUtil.resetClassLoaderReferences(t, cl, true);
t.setContextClassLoader(cl);
}
}
}
Expand Down

0 comments on commit 9db95f1

Please sign in to comment.