Class ExecutorKit

java.lang.Object
com.iohao.net.common.kit.concurrent.ExecutorKit

public final class ExecutorKit extends Object
Thread executor factory utilities.
Author:
渔民小镇
date:
2021-12-20
  • Method Details

    • newVirtualExecutor

      public static ExecutorService newVirtualExecutor(String name)
      Create a virtual thread executor.
      Parameters:
      name - thread name prefix
      Returns:
      the virtual thread executor
    • newVirtualExecutor

      public static ExecutorService newVirtualExecutor(String name, int start)
      Create a virtual thread executor.
      Parameters:
      name - thread name prefix
      start - starting value for the thread name counter
      Returns:
      the virtual thread executor
    • newVirtualExecutor

      public static ExecutorService newVirtualExecutor(ThreadFactory factory)
      Create a virtual thread executor.
      Parameters:
      factory - thread factory for virtual threads
      Returns:
      the virtual thread executor
    • newSingleThreadExecutor

      public static ExecutorService newSingleThreadExecutor(String namePrefix)
      Create a single-thread executor.
      Parameters:
      namePrefix - thread name prefix
      Returns:
      the single-thread executor
    • newSingleThreadExecutor

      public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory)
      Create a single-thread executor.
      Parameters:
      threadFactory - thread factory
      Returns:
      the single-thread executor
    • newCacheThreadPool

      public static ExecutorService newCacheThreadPool(String namePrefix)
      Create a cached thread pool.
      Parameters:
      namePrefix - thread name prefix
      Returns:
      the cached thread pool executor
    • newCacheThreadPool

      public static ExecutorService newCacheThreadPool(ThreadFactory threadFactory)
      Create a cached thread pool.
      Parameters:
      threadFactory - thread factory
      Returns:
      the cached thread pool executor
    • newFixedThreadPool

      public static ExecutorService newFixedThreadPool(int corePoolSize, ThreadFactory threadFactory)
      Create a fixed-size thread pool.
      Parameters:
      corePoolSize - pool size
      threadFactory - thread factory
      Returns:
      the fixed-size thread pool executor
    • newFixedThreadPool

      public static ExecutorService newFixedThreadPool(int corePoolSize, String namePrefix)
      Create a fixed-size thread pool.
      Parameters:
      corePoolSize - pool size
      namePrefix - thread name prefix
      Returns:
      the fixed-size thread pool executor
    • newSingleScheduled

      public static ScheduledExecutorService newSingleScheduled(ThreadFactory threadFactory)
      Create a single-thread scheduled executor.
      Parameters:
      threadFactory - thread factory
      Returns:
      the single-thread scheduled executor
    • newSingleScheduled

      public static ScheduledExecutorService newSingleScheduled(String namePrefix)
      Create a single-thread scheduled executor.
      Parameters:
      namePrefix - thread name prefix
      Returns:
      the single-thread scheduled executor
    • newScheduled

      public static ScheduledExecutorService newScheduled(int corePoolSize, String namePrefix)
      Create a scheduled executor with the specified pool size.
      Parameters:
      corePoolSize - pool size
      namePrefix - thread name prefix
      Returns:
      the scheduled executor
    • newScheduled

      public static ScheduledExecutorService newScheduled(int corePoolSize, ThreadFactory threadFactory)
      Create a scheduled executor with the specified pool size.
      Parameters:
      corePoolSize - pool size
      threadFactory - thread factory
      Returns:
      the scheduled executor
    • createThreadFactory

      public static ThreadFactory createThreadFactory(String namePrefix)
      Create a thread factory. Daemon is true by default.
      Parameters:
      namePrefix - thread name prefix
      Returns:
      the thread factory
    • createThreadFactory

      public static ThreadFactory createThreadFactory(@NonNull String namePrefix, boolean daemon)
      Create a thread factory.
      Parameters:
      namePrefix - thread name prefix
      daemon - whether threads are daemon threads
      Returns:
      the thread factory
    • createSigleThreadFactory

      public static ThreadFactory createSigleThreadFactory(@NonNull String name)
      Create a single-named daemon thread factory.
      Parameters:
      name - the fixed thread name
      Returns:
      the thread factory