Skip to content

Commit

Permalink
Issue #5859 - Use JVM PrivilegedThreadFactory instead.
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Mar 23, 2022
1 parent 036cbe8 commit 3c462c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -20,6 +20,7 @@

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.Executors;
import java.util.function.Supplier;

/**
Expand All @@ -32,7 +33,10 @@
* calling context - which contains ProtectionDomains that may
* reference the context classloader - and remembers it for the
* lifetime of the Thread.
*
* @deprecated use {@link Executors#privilegedThreadFactory()} instead.
*/
@Deprecated
class PrivilegedThreadFactory
{
/**
Expand All @@ -51,6 +55,6 @@ public T run()
{
return newThreadSupplier.get();
}
});
}, AccessController.getContext());
}
}
Expand Up @@ -25,6 +25,7 @@
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -103,6 +104,7 @@ public class QueuedThreadPool extends ContainerLifeCycle implements ThreadFactor
private final BlockingQueue<Runnable> _jobs;
private final ThreadGroup _threadGroup;
private final ThreadFactory _threadFactory;
private final ThreadFactory _privilegedThreadFactory = Executors.privilegedThreadFactory();
private String _name = "qtp" + hashCode();
private int _idleTimeout;
private int _maxThreads;
Expand Down Expand Up @@ -813,14 +815,13 @@ private boolean addCounts(int deltaThreads, int deltaIdle)
@Override
public Thread newThread(Runnable runnable)
{
return PrivilegedThreadFactory.newThread(() ->
return _privilegedThreadFactory.newThread(() ->
{
Thread thread = new Thread(_threadGroup, runnable);
thread.setDaemon(isDaemon());
thread.setPriority(getThreadsPriority());
thread.setName(_name + "-" + thread.getId());
thread.setContextClassLoader(getClass().getClassLoader());
return thread;
});
}

Expand Down

0 comments on commit 3c462c3

Please sign in to comment.