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
ConstructorDescriptionVirtualThreadGroup
(ThreadGroupType type, String name) Constructs the thread group without anysessionInfo
set, 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 ThreadData
Gets 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 ThreadGroup
Gets the system thread group when platform threads should be used.static final VirtualThreadGroup
The 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.boolean
setMaximumThreadPriority
(int maximumPriority) For platform threads, sets the maximum thread priority for the thread group.void
setSessionInfo
(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...boolean
Checks if virtual threads are used for this thread group.
Constructor Details
VirtualThreadGroup
Constructs the thread group without anysessionInfo
set, i.e. set tonull
initially.- 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,null
for none.- Throws:
IllegalArgumentException
- Ifstart
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
- Ifstart
is negative.
Method Details
getCurrentThreadData
Gets the inheritable thread data for the current thread.- Returns:
- The ThreadData, or
null
if 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
checkAccess
method of this thread group is called with no arguments; this may result in a security exception.If the
maximumPriority
argument is less thanThread.MIN_PRIORITY
or 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
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 tomaximumPriority
.) Then this method is called recursively, withmaximumPriority
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
Gets the ThreadGroup associated.- Returns:
- The platform ThreadGroup if not using virtual threads, otherwise
null
when 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
- IfsessionInfo
isnull
.IllegalStateException
- If thesessionInfo
has 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
null
if 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:
The
- runnable.- Returns:
- The unstarted thread.
startThread
Creates a new started thread for the thread group in question.- Parameters:
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, ornull
for 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, ornull
for none.priority
- The thread priority (ignored for virtual threads).- Returns:
- The started thread.
- Throws:
IllegalArgumentException
- if the priority is not in the rangeThread#MIN_PRIORITY
toThread#MAX_PRIORITY
.
toString
Returns a string identifying this VirtualThreadGroup, etc...