Class ThreadCreator


  • public class ThreadCreator
    extends java.lang.Object
    Since:
    Helper class to create regular or virtual threads. Virtual threads are not supported for versions less than Java 17.
    Author:
    Bela Ban
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadCreator()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Thread createThread​(java.lang.Runnable r, java.lang.String name, boolean daemon, boolean virtual)  
      static java.util.concurrent.ExecutorService createThreadPool​(int min_threads, int max_threads, long keep_alive_time, boolean virtual_threads, Log log)  
      static java.util.concurrent.ExecutorService createThreadPool​(int min_threads, int max_threads, long keep_alive_time, java.lang.String rejection_policy, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, ThreadFactory factory, boolean useVirtualThreads, Log log)  
      protected static java.lang.invoke.MethodHandle getCreateVThreadHandle()  
      protected static java.lang.invoke.MethodHandle getNewVirtualThreadFactoryHandle()  
      protected static java.lang.Class<?> getOfVirtualClass()  
      protected static java.lang.invoke.MethodHandle getOfVirtualHandle()  
      static boolean hasVirtualThreads()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThreadCreator

        public ThreadCreator()
    • Method Detail

      • hasVirtualThreads

        public static boolean hasVirtualThreads()
      • getCreateVThreadHandle

        protected static java.lang.invoke.MethodHandle getCreateVThreadHandle()
      • getOfVirtualClass

        protected static java.lang.Class<?> getOfVirtualClass()
      • getOfVirtualHandle

        protected static java.lang.invoke.MethodHandle getOfVirtualHandle()
      • getNewVirtualThreadFactoryHandle

        protected static java.lang.invoke.MethodHandle getNewVirtualThreadFactoryHandle()
      • createThread

        public static java.lang.Thread createThread​(java.lang.Runnable r,
                                                    java.lang.String name,
                                                    boolean daemon,
                                                    boolean virtual)
      • createThreadPool

        public static java.util.concurrent.ExecutorService createThreadPool​(int min_threads,
                                                                            int max_threads,
                                                                            long keep_alive_time,
                                                                            boolean virtual_threads,
                                                                            Log log)
      • createThreadPool

        public static java.util.concurrent.ExecutorService createThreadPool​(int min_threads,
                                                                            int max_threads,
                                                                            long keep_alive_time,
                                                                            java.lang.String rejection_policy,
                                                                            java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
                                                                            ThreadFactory factory,
                                                                            boolean useVirtualThreads,
                                                                            Log log)