Class ExecutorsHelper

java.lang.Object
velox.api.layer1.common.helper.ExecutorsHelper

public class ExecutorsHelper extends Object
  • Constructor Details

    • ExecutorsHelper

      public ExecutorsHelper()
  • Method Details

    • newOnDemandSingleThreadExecutor

      public static ThreadPoolExecutor newOnDemandSingleThreadExecutor(String name)
      Similar to Executors.newSingleThreadExecutor(), but limits threads lifetime and sets a name
    • newOnDemandSingleThreadPriorityExecutor

      public static ThreadPoolExecutor newOnDemandSingleThreadPriorityExecutor(String name)
      Respects priority of runnables if those are instances of ExecutorsHelper.PrioritizedRunnable, limits threads lifetime, sets a name. Otherwise similar to Executors.newSingleThreadExecutor()
    • newSingleThreadExecutor

      public static ThreadPoolExecutor newSingleThreadExecutor(String name)
      Similar to Executors.newSingleThreadExecutor(), but sets a name and isn't wrapped in FinalizableDelegatedExecutorService
    • newSingleThreadExecutor

      public static ThreadPoolExecutor newSingleThreadExecutor(String name, Consumer<Boolean> queueEmptyCallback)
      Similar to Executors.newSingleThreadExecutor(), but sets a name and isn't wrapped in FinalizableDelegatedExecutorService
    • newThreadPoolExecutor

      public static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name, Consumer<Boolean> queueEmptyCallback)
    • newThreadPoolExecutor

      public static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name)
    • newFixedThreadPoolExecutor

      public static ThreadPoolExecutor newFixedThreadPoolExecutor(int poolSize, String name)
    • newThreadPoolPriorityExecutor

      public static ThreadPoolExecutor newThreadPoolPriorityExecutor(int corePoolSize, int maximumPoolSize, String name)
    • newThreadPoolExecutor

      public static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name, BlockingQueue<Runnable> queue)
    • newThreadPoolExecutor

      public static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name, BlockingQueue<Runnable> queue, RejectedExecutionHandler handler)
    • newScheduledThreadPool

      public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, String name)
    • newOnDemandPriorityThreadPoolExecutor

      public static velox.api.layer1.common.helper.PriorityThreadPoolExecutor newOnDemandPriorityThreadPoolExecutor(String name)
    • executeIfNotShutdown

      public static boolean executeIfNotShutdown(ExecutorService executor, Runnable command)
      Executes the given command the same as Executor.execute(Runnable), but only if the executor is not shutdown and returns true. Otherwise, the command is not executed and the method returns false.
      Parameters:
      executor - executor to be used to run the task
      command - the runnable task
      Returns:
      true if the command was executed, false if the executor is shutdown
    • scheduleIfNotShutDown

      public static ScheduledFuture<?> scheduleIfNotShutDown(ScheduledExecutorService executor, Runnable command, long delay, TimeUnit unit)
      Schedules the given command for execution after the specified delay, but only if the executor is not shut down. If the executor is still active, the command is scheduled and a ScheduledFuture<?> representing pending completion of the task is returned. If the executor is shut down, the command is not scheduled, and the method returns null.
      Parameters:
      executor - The ScheduledExecutorService to be used to schedule the task.
      command - The Runnable task to be scheduled.
      delay - The delay after which the command is to be executed.
      unit - The TimeUnit of the delay parameter.
      Returns:
      A ScheduledFuture<?> representing pending completion of the task, or null if the executor is shut down and the task could not be scheduled.
    • invokeAllIfNotShutdown

      public static <T> List<Future<T>> invokeAllIfNotShutdown(ExecutorService executor, Collection<? extends Callable<T>> tasks)
      Executes given tasks the same as ExecutorService.invokeAll(Collection), but only if the executor is not shutdown and returns a list of Futures representing pending completion of the tasks. Otherwise, the command is not executed and the method returns empty list.
      Type Parameters:
      T - type of the result
      Parameters:
      executor - executor to be used to run tasks
      tasks - callable task to be executed
      Returns:
      a list of Futures representing pending completion of the tasks, or empty list if the executor is shutdown