Class VirtualThreadGroup

java.lang.Object
com.iizix.virtual.VirtualThreadGroup

public class VirtualThreadGroup extends Object
The VirtualThreadGroup is used to manage native and virtual threads for
  • an receiving end-point in the server,
  • a server session with another server,
  • an application session,
  • a client session, or
  • a VirtualSpace Viewer session for development servers.
    • What these thread groups have in common is that the threads used needs to be tracked and also hold "thread local" data (for virtual threads). The amount of "parked" threads, being virtual or not is set per thread group. This also applies to precreated non-started threads (virtual or native).

      It should be noted that virtual threads are in general preferred to native threads.

Author:
Christopher Mindus
  • Constructor Details

    • VirtualThreadGroup

      public VirtualThreadGroup(ThreadGroupType type, String name)
      Constructs the thread group without any sessionInfo set, i.e. set to null initially.
      Parameters:
      type - The type of thread group.
      name - The name of the thread group, typically used for logging.
    • VirtualThreadGroup

      public VirtualThreadGroup(ThreadGroupType type, String name, SessionInfo sessionInfo)
      Constructs the thread group.
      Parameters:
      type - The type of thread group.
      name - The name of the thread group, typically used for logging.
      sessionInfo - The session information, null for none.
      Throws:
      IllegalArgumentException - If start is negative.
    • VirtualThreadGroup

      public VirtualThreadGroup(ThreadGroupType type, String name, SessionInfo sessionInfo, ClassLoader contextClassLoader)
      Constructs the thread group.
      Parameters:
      type - The type of thread group.
      name - The name of the thread group, typically used for logging.
      sessionInfo - The session information, null for none.
      contextClassLoader - The context class loader for threads, null for none.
      Throws:
      IllegalArgumentException - If start is negative.
  • Method Details

    • getCurrentThreadData

      public static ThreadData getCurrentThreadData()
      Gets the inheritable thread data for the current thread.
      Returns:
      The ThreadData, or null if not found.
    • getSystemThreadGroup

      public static final ThreadGroup getSystemThreadGroup()
      Gets the system thread group when platform threads should be used.
      Returns:
      The topmost thread group named IIZI.
    • getSystemVirtualThreadGroup

      public static final VirtualThreadGroup getSystemVirtualThreadGroup()
      The VirtualThreadGroup of the system, being of platforms type.
      Returns:
      The system VirtualThreadGroup.
    • getName

      public String getName()
      Gets the name of the VirtualThreadGroup.
      Returns:
      The name.
    • getType

      public ThreadGroupType getType()
      Gets the type of the virtual thread group.
      Returns:
      The type.
    • usesVirtualThreads

      public boolean usesVirtualThreads()
      Checks if virtual threads are used for this thread group.
    • setMaximumThreadPriority

      public boolean setMaximumThreadPriority(int maximumPriority)
      For platform threads, sets the maximum thread priority for the thread group. If this thread group uses virtual threads, this call performs nothing.

      First, the checkAccess method of this thread group is called with no arguments; this may result in a security exception.

      If the maximumPriority argument is less than Thread.MIN_PRIORITY or greater than Thread.MAX_PRIORITY, the maximum priority of the group remains unchanged.

      Otherwise, the priority of this ThreadGroup object is set to the smaller of the specified maximumPriority and the maximum permitted priority of the parent of this thread group. (If this thread group is the system thread group, which has no parent, then its maximum priority is simply set to maximumPriority.) Then this method is called recursively, with maximumPriority as its argument, for every thread group that belongs to this thread group.

      Parameters:
      maximumPriority - The new maximum priority of the thread group.
      Returns:
      true for success, false for failure.
      Throws:
      SecurityException - If the current thread cannot modify this thread group.
      See Also:
    • getThreadGroup

      public ThreadGroup getThreadGroup()
      Gets the ThreadGroup associated.
      Returns:
      The platform ThreadGroup if not using virtual threads, otherwise null when the VirtualThreadGroup instance used virtual threads.
    • getThreadFactory

      public ThreadFactory getThreadFactory()
      Gets the ThreadFactory initialized for the ThreadGroupType. It can be platform or virtual threads factory.
      Returns:
      The thread factory.
    • setSessionInfo

      public void setSessionInfo(SessionInfo sessionInfo)
      The session information if not previously set. It DOES NOT affect the current thread.
      Parameters:
      sessionInfo - The session information.
      Throws:
      NullPointerException - If sessionInfo is null.
      IllegalStateException - If the sessionInfo has been set before.
    • getCurrentThreadLoggers

      public Loggers getCurrentThreadLoggers()
      Gets the Loggers used for the current thread.
      Returns:
      The Loggers instance, never null.
    • getCurrentThreadSessionInfo

      public SessionInfo getCurrentThreadSessionInfo()
      Gets the session information for the current thread.
      Returns:
      The SessionInfo instance, or null if none is set.
    • newExecutorService

      public ExecutorService newExecutorService()
      Gets a new executor service associated with this thread group. Please note that the executor service should be closed once it has completed its mission.
      Returns:
      The virtual or platform executor service associated with this group.
    • createThread

      public Thread createThread(Runnable runnable)
      Creates a new unstarted thread for the thread group in question.
      Parameters:
      runnable - The runnable.
      Returns:
      The unstarted thread.
    • startThread

      public Thread startThread(Runnable runnable)
      Creates a new started thread for the thread group in question.
      Parameters:
      runnable - The runnable.
      Returns:
      The started thread.
    • startThread

      public Thread startThread(Runnable runnable, String name)
      Creates a new started thread for the thread group in question.
      Parameters:
      runnable - The runnable.
      name - The thread name, or null for none.
      Returns:
      The started thread.
    • startThread

      public Thread startThread(Runnable runnable, String name, int priority)
      Creates a new started thread for the thread group in question.
      Parameters:
      runnable - The runnable.
      name - The thread name, or null for none.
      priority - The thread priority (ignored for virtual threads).
      Returns:
      The started thread.
      Throws:
      IllegalArgumentException - if the priority is not in the range Thread#MIN_PRIORITY to Thread#MAX_PRIORITY.
    • toString

      public String toString()
      Returns a string identifying this VirtualThreadGroup, etc...
      Overrides:
      toString in class Object
      Returns:
      A string identifying this VirtualThreadGroup.