Skip to content

Commit

Permalink
Attempt to set the TCCL on the IO Threads after restart
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Jul 2, 2020
1 parent c27fb26 commit ab072e9
Showing 1 changed file with 35 additions and 0 deletions.
Expand Up @@ -22,6 +22,7 @@
import org.wildfly.common.cpu.ProcessorInfo;

import io.netty.channel.EventLoopGroup;
import io.netty.util.concurrent.EventExecutor;
import io.quarkus.runtime.IOThreadDetector;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.ShutdownContext;
Expand All @@ -32,6 +33,7 @@
import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.eventbus.EventBusOptions;
Expand All @@ -47,6 +49,8 @@ public class VertxCoreRecorder {

static volatile VertxSupplier vertx;

static volatile int blockingThreadPoolSize;

public Supplier<Vertx> configureVertx(VertxConfiguration config,
LaunchMode launchMode, ShutdownContext shutdown, List<Consumer<VertxOptions>> customizers) {
vertx = new VertxSupplier(config, customizers);
Expand All @@ -63,6 +67,36 @@ public void run() {
return vertx;
}

private void tryCleanTccl(Vertx devModeVertx) {
//this is a best effort attempt to clean out the old TCCL from
ClassLoader cl = Thread.currentThread().getContextClassLoader();
for (int i = 0; i < blockingThreadPoolSize; ++i) {
devModeVertx.executeBlocking(new Handler<Promise<Object>>() {
@Override
public void handle(Promise<Object> event) {
Thread.currentThread().setContextClassLoader(cl);
try {
Thread.sleep(50);
} catch (InterruptedException e) {

}
}
}, null);
}
EventLoopGroup group = ((VertxImpl) devModeVertx).getEventLoopGroup();
for (EventExecutor i : group) {
i.execute(new Runnable() {

@Override
public void run() {
Thread.currentThread().setContextClassLoader(cl);
}

});
}

}

public IOThreadDetector detector() {
return new IOThreadDetector() {
@Override
Expand Down Expand Up @@ -149,6 +183,7 @@ private static VertxOptions convertToVertxOptions(VertxConfiguration conf, Vertx
.setClassPathResolvingEnabled(conf.classpathResolving));
options.setWorkerPoolSize(conf.workerPoolSize);
options.setInternalBlockingPoolSize(conf.internalBlockingPoolSize);
blockingThreadPoolSize = conf.internalBlockingPoolSize;

options.setBlockedThreadCheckInterval(conf.warningExceptionTime.toMillis());
if (conf.eventLoopsPoolSize.isPresent()) {
Expand Down

0 comments on commit ab072e9

Please sign in to comment.