Class MRJExecutors

java.lang.Object
org.stianloader.mrjmania.MRJExecutors

public class MRJExecutors extends Object
Polyfills regarding threads, Executors and thread pools.
  • Method Details

    • getVirtualExecutorType

      @NotNull @Contract(pure=true) public static @NotNull String getVirtualExecutorType()
      Gets a String representation of the getVirtualExecutor() executor used. Or, it returns which pool is being used.
      Returns:
      A String representation of the Executor 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

      @NotNull @Contract(pure=true) public static @NotNull Executor getVirtualExecutor()
      Returns an executor that may or may not be virtual, see supportsVirtualExecutors().

      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.