Class ExecutorUtils

java.lang.Object
id.luckynetwork.lyrams.lyralibs.core.utils.ExecutorUtils

public class ExecutorUtils extends Object
  • Constructor Details

    • ExecutorUtils

      public ExecutorUtils()
  • Method Details

    • getFixedExecutorService

      public ExecutorService getFixedExecutorService(String name)
      > It creates a fixed size thread pool with a custom thread factory that sets the thread name and a custom uncaught exception handler that logs the exception
      Parameters:
      name - The name of the thread pool.
      Returns:
      A fixed thread pool executor service.
    • getFixedExecutorService

      public ExecutorService getFixedExecutorService(String name, int poolSize)
      > It creates a fixed size thread pool with a custom thread factory that sets the thread name and a custom uncaught exception handler that logs the exception
      Parameters:
      name - The name of the thread pool.
      poolSize - The size of the thread pool.
      Returns:
      A fixed thread pool executor service.
    • getFixedScheduledExecutorService

      public ScheduledExecutorService getFixedScheduledExecutorService(String name)
      > It creates a new `ScheduledExecutorService` with a fixed pool size, and a `ThreadFactory` that creates threads with a name format of `name` and a `LuckyThreadFactory` that creates threads with a name format of `name`
      Parameters:
      name - The name of the thread pool.
      Returns:
      A ScheduledExecutorService
    • getFixedScheduledExecutorService

      public ScheduledExecutorService getFixedScheduledExecutorService(String name, int poolSize)
      > It creates a new `ScheduledExecutorService` with a fixed pool size, and a `ThreadFactory` that creates threads with a name format of `name` and a `LuckyThreadFactory` that creates threads with a name format of `name`
      Parameters:
      name - The name of the thread pool.
      poolSize - The size of the thread pool.
      Returns:
      A ScheduledExecutorService
    • getUnlimitedExecutorService

      public ExecutorService getUnlimitedExecutorService(String name)
      Create a thread pool executor with an unlimited number of threads, and a thread factory that creates threads with the given name.
      Parameters:
      name - The name of the thread pool.
      Returns:
      An ExecutorService
    • getUnlimitedScheduledExecutorService

      public ScheduledExecutorService getUnlimitedScheduledExecutorService(String name)
      Create a scheduled executor service with an unlimited number of threads, and allow the threads to time out.
      Parameters:
      name - The name of the thread pool.
      Returns:
      A ScheduledExecutorService
    • getSingleThreadedExecutor

      public ExecutorService getSingleThreadedExecutor(String name)
      Create a single threaded executor with a thread factory that creates threads with the given name and a custom uncaught exception handler.
      Parameters:
      name - The name of the thread pool.
      Returns:
      A single threaded executor service.
    • getSingleThreadedScheduledExecutor

      public ScheduledExecutorService getSingleThreadedScheduledExecutor(String name)
      Create a single threaded scheduled executor with a custom thread factory that sets the thread name and uses LuckyThreadFactory to set the thread priority.
      Parameters:
      name - The name of the thread.
      Returns:
      A single threaded scheduled executor service.
    • getWorkStealingExecutor

      public ExecutorService getWorkStealingExecutor(String name)
      It creates a ForkJoinPool with a custom thread factory that renames the threads
      Parameters:
      name - The name of the thread pool.
      Returns:
      A work stealing executor service.