Class PrivilegedThreadFactory

java.lang.Object
org.eclipse.jetty.util.thread.PrivilegedThreadFactory

class PrivilegedThreadFactory extends Object
Convenience class to ensure that a new Thread is created inside a privileged block. This prevents the Thread constructor from pinning the caller's context classloader. This happens when the Thread constructor takes a snapshot of the current calling context - which contains ProtectionDomains that may reference the context classloader - and remembers it for the lifetime of the Thread.
  • Constructor Details

    • PrivilegedThreadFactory

      PrivilegedThreadFactory()
  • Method Details

    • newThread

      static <T extends Thread> T newThread(Supplier<T> newThreadSupplier)
      Use a Supplier to make a new thread, calling it within a privileged block to prevent classloader pinning.
      Parameters:
      newThreadSupplier - a Supplier to create a fresh thread
      Returns:
      a new thread, protected from classloader pinning.