Class Threads

java.lang.Object
com.sun.management.Threads

public class Threads extends Object
This class consists exclusively of static methods that provide access to threads in the Java virtual machine. It is intended for use by debugging and monitoring tools.
Since:
99
  • Method Details

    • virtualThreads

      public static Stream<Thread> virtualThreads()
      Returns the stream of the virtual threads that have been started but have not terminated. Returns an empty stream if tracking of virtual threads is not enabled.

      This method requires that the Java virtual machine be started with the system property "jdk.trackAllVirtualThreads" set to the value of "true", otherwise virtual threads are not tracked.

      Returns:
      the stream of virtual threads
      Throws:
      SecurityException - if denied by the security manager
    • executors

      public static List<Threads.ThreadExecutor> executors(Thread thread)
      Returns the list of active thread executors owned by the given thread. The list is ordered, enclosing executors before nested executors.
      Parameters:
      thread - the thread
      Returns:
      the list of active thread executors owned by the thread
      Throws:
      SecurityException - if denied by the security manager
      See Also:
      Executors.newThreadExecutor(ThreadFactory)