Class PrivilegedThreadFactory


  • class PrivilegedThreadFactory
    extends java.lang.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.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <T extends java.lang.Thread>
      T
      newThread​(java.util.function.Supplier<T> newThreadSupplier)
      Use a Supplier to make a new thread, calling it within a privileged block to prevent classloader pinning.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PrivilegedThreadFactory

        PrivilegedThreadFactory()
    • Method Detail

      • newThread

        static <T extends java.lang.Thread> T newThread​(java.util.function.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.