Top Description Constructors Methods
org.eclipse.jetty.util.thread

pack-priv Class PrivilegedThreadFactory

extends Object
Class Inheritance
Imports
java.security.PrivilegedAction, .ProtectionDomain, java.util.function.Supplier, org.eclipse.jetty.util.security.SecurityUtils

Convenience Thread factory that ensure threads are created without referencing any web application ClassLoader.

Up to Java 17, the Thread constructor was taking a snapshot of the calling context, which may contain a ProtectionDomain that references a web application ClassLoader (for example if the creation of the Thread was triggered by some operation performed by the web application). The Thread might then be pooled and prevent the web application ClassLoader to be garbage collected when the web application is undeployed. For this reason, Threads must be created in a privileged action, which restricts the calling context to just the caller frame, not all the frames in the stack.

Since Java 18 and the removal of the Java security manager and related classes by JEP 411, Threads do not retain the calling context, so there is no need to create them in a privileged action.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <T extends Thread> T

Returns:

a new Thread without retaining the calling context
newThread
(PrivilegedAction<T>
the action that creates the Thread
creator
)

Creates a new Thread from the given Supplier, without retaining the calling context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PrivilegedThreadFactoryback to summary
private PrivilegedThreadFactory()

Method Detail

newThreadback to summary
pack-priv static <T extends Thread> T newThread(PrivilegedAction<T> creator)

Creates a new Thread from the given Supplier, without retaining the calling context.

Parameters
creator:PrivilegedAction<T>

the action that creates the Thread

Returns:T

a new Thread without retaining the calling context