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 SummaryConstructors
- Method SummaryModifier and TypeMethodDescription- static booleanReturns if the virtual threads are supported on the platform.- static booleanChecks if the current thread is virtual.- static boolean- isVirtualThread- (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 Thread- startThread- (Runnable runnable) Starts a new "real" thread or a virtual thread depending on JVM support.- static Thread- startThread- (Runnable runnable, String name) Starts a new "real" thread or a virtual thread depending on JVM support.- static Thread- startThread- (Runnable runnable, String name, int priority) Starts a new "real" thread or a virtual thread depending on JVM support.
- Constructor Details- VirtualThreadspublic VirtualThreads()
 
- Method Details- areVirtualThreadsSupportedpublic static boolean areVirtualThreadsSupported()Returns if the virtual threads are supported on the platform.- Returns:
- trueif supported,- falseotherwise.
 
- startThreadStarts a new "real" thread or a virtual thread depending on JVM support. The thread is started as a daemon thread with the priority- Thread.NORM_PRIORITY, but only when not a virtual thread.- Parameters:
- runnnable- The runnable.
- Returns:
- The new started thread.
 
- startThreadStarts a new "real" thread or a virtual thread depending on JVM support. The thread is started as a daemon thread with the priority- Thread.NORM_PRIORITY, but only when not a virtual thread.- Parameters:
- name- The thread name (or- null for none.
- runnnable- The runnable.
- Returns:
- The new started thread.
 
- startThreadStarts a new "real" thread or a virtual thread depending on JVM support. The thread is started as a daemon thread with the- priorityspecified, but only when not a virtual thread.- Parameters:
- name- The thread name (or- null for none.
- priority- The thread priority (always ignored for virtual threads).
- runnnable- The runnable.
- Returns:
- The new started thread.
 
- isVirtualThreadChecks if the thread is virtual.- Parameters:
- thread- The thread to test.
- Returns:
- trueif thread is virtual,- falseotherwise.
 
- isVirtualCurrentThreadpublic static boolean isVirtualCurrentThread()Checks if the current thread is virtual.- Returns:
- trueif thread is virtual,- falseotherwise.
 
- newExecutorForProcessorCreates a new executors service based on virtual threads or the number of CPU's available.- Executors.newVirtualThreadPerTaskExecutor()creates an- ExecutorServicethat 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.