Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty 9.4.x 5859 classloader leak queuedthreadpool #5894

Merged
Merged
Expand Up @@ -689,6 +689,7 @@ public Thread newThread(Runnable runnable)
thread.setDaemon(isDaemon());
thread.setPriority(getThreadsPriority());
thread.setName(_name + "-" + thread.getId());
thread.setContextClassLoader(QueuedThreadPool.class.getClassLoader());
janbartel marked this conversation as resolved.
Show resolved Hide resolved
return thread;
}

Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StacklessLogging;
import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -833,6 +834,24 @@ public void testDump() throws Exception
assertThat(count(dump, "QueuedThreadPoolTest.lambda$testDump$"), is(1));
}

@Test
public void testContextClassLoader() throws Exception
{
QueuedThreadPool tp = new QueuedThreadPool();
tp.setMinThreads(1);
tp.setMaxThreads(2);
tp.setIdleTimeout(1000);
tp.setThreadsPriority(Thread.NORM_PRIORITY - 1);
try (StacklessLogging stackless = new StacklessLogging(QueuedThreadPool.class))
{
tp.start();
tp.execute(() ->
{
assertThat(Thread.currentThread().getContextClassLoader(), Matchers.equalTo(QueuedThreadPool.class.getClassLoader()));
});
}
}
janbartel marked this conversation as resolved.
Show resolved Hide resolved

private int count(String s, String p)
{
int c = 0;
Expand Down