Package org.stianloader.mrjmania
Class MRJExecutors
java.lang.Object
org.stianloader.mrjmania.MRJExecutors
Polyfills regarding threads,
Executors and thread pools.-
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull ExecutorReturns an executor that may or may not be virtual, seesupportsVirtualExecutors().static @NotNull StringGets aStringrepresentation of thegetVirtualExecutor()executor used.static booleanReturns whether virtual threads are enabled/support in the given release.
-
Method Details
-
getVirtualExecutorType
Gets aStringrepresentation of thegetVirtualExecutor()executor used. Or, it returns which pool is being used. -
supportsVirtualExecutors
@Contract(pure=true) public static boolean supportsVirtualExecutors()Returns whether virtual threads are enabled/support in the given release.- Returns:
- Returns false for Java 8 to Java 20 (as per
MRJMania.getMRJVersion()), true for J21 and above.
-
getVirtualExecutor
Returns an executor that may or may not be virtual, seesupportsVirtualExecutors().Note that the returned executor will be from the
ForkJoinPool.commonPool()by default if not virtual, so it might be unwise to use it for non-short-lived tasks else it might clog up other processes.Further, if the task is indeed virtual, it will spin up a virtual thread by task. This might not be intended/great either, depending on circumstances.
- Returns:
- The virtual executor to use.
-