Package com.iizix.virtual
Class VirtualThreads
java.lang.Object
com.iizix.virtual.VirtualThreads
Support for better concurrency support in IIZI by means of VirtualThreads Threads in the JVM.
It is the early form of virtual threads for the IIZI system supported by Java 19 and better. Functionality to support it must be enabled as "--enabled-preview" as a parameter to the JVM.
A property "iizi.virtualthreads=false" will turn off the support regardless of JVM settings, e.g. using the Java parameter -Diizi.virtualthreads=false.
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic booleanReturns if the virtual threads are supported on the platform.static booleanChecks if the current thread is virtual.static booleanisVirtualThread(Thread thread) Checks if the thread is virtual.static ExecutorServiceCreates a new executors service based on virtual threads or the number of CPU's available.static ThreadstartThread(Runnable runnable) Starts a new "real" thread or a virtual thread depending on JVM support.static ThreadstartThread(Runnable runnable, String name) Starts a new "real" thread or a virtual thread depending on JVM support.static ThreadstartThread(Runnable runnable, String name, int priority) Starts a new "real" thread or a virtual thread depending on JVM support.
Constructor Details
VirtualThreads
public VirtualThreads()
Method Details
areVirtualThreadsSupported
public static boolean areVirtualThreadsSupported()Returns if the virtual threads are supported on the platform.- Returns:
trueif supported,falseotherwise.
startThread
Starts a new "real" thread or a virtual thread depending on JVM support. The thread is started as a daemon thread with the priorityThread.NORM_PRIORITY, but only when not a virtual thread.- Parameters:
runnnable- The runnable.- Returns:
- The new started thread.
startThread
Starts a new "real" thread or a virtual thread depending on JVM support. The thread is started as a daemon thread with the priorityThread.NORM_PRIORITY, but only when not a virtual thread.- Parameters:
name- The thread name (ornull for none.runnnable- The runnable.- Returns:
- The new started thread.
startThread
Starts a new "real" thread or a virtual thread depending on JVM support. The thread is started as a daemon thread with thepriorityspecified, but only when not a virtual thread.- Parameters:
name- The thread name (ornull for none.priority- The thread priority (always ignored for virtual threads).runnnable- The runnable.- Returns:
- The new started thread.
isVirtualThread
Checks if the thread is virtual.- Parameters:
thread- The thread to test.- Returns:
trueif thread is virtual,falseotherwise.
isVirtualCurrentThread
public static boolean isVirtualCurrentThread()Checks if the current thread is virtual.- Returns:
trueif thread is virtual,falseotherwise.
newExecutorForProcessor
Creates a new executors service based on virtual threads or the number of CPU's available.Executors.newVirtualThreadPerTaskExecutor()creates anExecutorServicethat creates a new virtual thread for each task.In the case if virtual threads is not supported, the return value will be a new
new ForkJoinPool().- Returns:
- The executor service.