Class VirtualThreadGroup
- 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 Summary
ConstructorsConstructorDescriptionVirtualThreadGroup(ThreadGroupType type, String name) Constructs the thread group without anysessionInfoset, i.e.VirtualThreadGroup(ThreadGroupType type, String name, SessionInfo sessionInfo) Constructs the thread group.VirtualThreadGroup(ThreadGroupType type, String name, SessionInfo sessionInfo, ClassLoader contextClassLoader) Constructs the thread group.Method Summary
Modifier and TypeMethodDescriptioncreateThread(Runnable runnable) Creates a new unstarted thread for the thread group in question.static ThreadDataGets the inheritable thread data for the current thread.Gets the Loggers used for the current thread.Gets the session information for the current thread.getName()Gets the name of the VirtualThreadGroup.static final ThreadGroupGets the system thread group when platform threads should be used.static final VirtualThreadGroupThe VirtualThreadGroup of the system, being of platforms type.Gets the ThreadFactory initialized for the ThreadGroupType.Gets the ThreadGroup associated.getType()Gets the type of the virtual thread group.Gets a new executor service associated with this thread group.booleansetMaximumThreadPriority(int maximumPriority) For platform threads, sets the maximum thread priority for the thread group.voidsetSessionInfo(SessionInfo sessionInfo) The session information if not previously set.startThread(Runnable runnable) Creates a new started thread for the thread group in question.startThread(Runnable runnable, String name) Creates a new started thread for the thread group in question.startThread(Runnable runnable, String name, int priority) Creates a new started thread for the thread group in question.toString()Returns a string identifying this VirtualThreadGroup, etc...booleanChecks if virtual threads are used for this thread group.
Constructor Details
VirtualThreadGroup
Constructs the thread group without anysessionInfoset, i.e. set tonullinitially.- Parameters:
type- The type of thread group.name- The name of the thread group, typically used for logging.
VirtualThreadGroup
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,nullfor none.- Throws:
IllegalArgumentException- Ifstartis 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,nullfor none.contextClassLoader- The context class loader for threads,nullfor none.- Throws:
IllegalArgumentException- Ifstartis negative.
Method Details
getCurrentThreadData
Gets the inheritable thread data for the current thread.- Returns:
- The ThreadData, or
nullif not found.
getSystemThreadGroup
Gets the system thread group when platform threads should be used.- Returns:
- The topmost thread group named IIZI.
getSystemVirtualThreadGroup
The VirtualThreadGroup of the system, being of platforms type.- Returns:
- The system VirtualThreadGroup.
getName
Gets the name of the VirtualThreadGroup.- Returns:
- The name.
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
checkAccessmethod of this thread group is called with no arguments; this may result in a security exception.If the
maximumPriorityargument is less thanThread.MIN_PRIORITYor greater thanThread.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
maximumPriorityand 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 tomaximumPriority.) Then this method is called recursively, withmaximumPriorityas its argument, for every thread group that belongs to this thread group.- Parameters:
maximumPriority- The new maximum priority of the thread group.- Returns:
truefor success,falsefor failure.- Throws:
SecurityException- If the current thread cannot modify this thread group.- See Also:
getThreadGroup
Gets the ThreadGroup associated.- Returns:
- The platform ThreadGroup if not using virtual threads, otherwise
nullwhen the VirtualThreadGroup instance used virtual threads.
getThreadFactory
Gets the ThreadFactory initialized for the ThreadGroupType. It can be platform or virtual threads factory.- Returns:
- The thread factory.
setSessionInfo
The session information if not previously set. It DOES NOT affect the current thread.- Parameters:
sessionInfo- The session information.- Throws:
NullPointerException- IfsessionInfoisnull.IllegalStateException- If thesessionInfohas been set before.
getCurrentThreadLoggers
Gets the Loggers used for the current thread.- Returns:
- The Loggers instance, never
null.
getCurrentThreadSessionInfo
Gets the session information for the current thread.- Returns:
- The SessionInfo instance, or
nullif none is set.
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
Creates a new unstarted thread for the thread group in question.- Parameters:
runnable- The runnable.- Returns:
- The unstarted thread.
startThread
Creates a new started thread for the thread group in question.- Parameters:
runnable- The runnable.- Returns:
- The started thread.
startThread
Creates a new started thread for the thread group in question.- Parameters:
runnable- The runnable.name- The thread name, ornullfor none.- Returns:
- The started thread.
startThread
Creates a new started thread for the thread group in question.- Parameters:
runnable- The runnable.name- The thread name, ornullfor none.priority- The thread priority (ignored for virtual threads).- Returns:
- The started thread.
- Throws:
IllegalArgumentException- if the priority is not in the rangeThread#MIN_PRIORITYtoThread#MAX_PRIORITY.
toString
Returns a string identifying this VirtualThreadGroup, etc...