Skip to content

Commit

Permalink
Issue #5859 Post review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel committed Jan 18, 2021
1 parent f60cf57 commit 596444f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -689,7 +689,7 @@ public Thread newThread(Runnable runnable)
thread.setDaemon(isDaemon());
thread.setPriority(getThreadsPriority());
thread.setName(_name + "-" + thread.getId());
thread.setContextClassLoader(QueuedThreadPool.class.getClassLoader());
thread.setContextClassLoader(this.getClass().getClassLoader());
return thread;
}

Expand Down
Expand Up @@ -19,6 +19,8 @@
package org.eclipse.jetty.util.thread;

import java.io.Closeable;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -839,16 +841,26 @@ public void testContextClassLoader() throws Exception
{
QueuedThreadPool tp = new QueuedThreadPool();
tp.setMinThreads(1);
tp.setMaxThreads(2);
tp.setMaxThreads(3);
tp.setIdleTimeout(1000);
tp.setThreadsPriority(Thread.NORM_PRIORITY - 1);
try (StacklessLogging stackless = new StacklessLogging(QueuedThreadPool.class))
{
tp.start();
tp.execute(() ->
//change the current thread's classloader to something else
Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[] {}));

//create a new thread
Thread t = tp.newThread(() ->
{
//the executing thread should be still set to the classloader of the QueuedThreadPool,
//not that of the thread that created this thread.
assertThat(Thread.currentThread().getContextClassLoader(), Matchers.equalTo(QueuedThreadPool.class.getClassLoader()));
});

//new thread should be set to the classloader of the QueuedThreadPool
assertThat(t.getContextClassLoader(), Matchers.equalTo(QueuedThreadPool.class.getClassLoader()));

t.start();
}
}

Expand Down

0 comments on commit 596444f

Please sign in to comment.