Package velox.api.layer1.common.helper
Class ExecutorsHelper
java.lang.Object
velox.api.layer1.common.helper.ExecutorsHelper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRunnable with an integer priority. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanexecuteIfNotShutdown(ExecutorService executor, Runnable command) Executes the given command the same asExecutor.execute(Runnable), but only if the executor is not shutdown and returns true.invokeAllIfNotShutdown(ExecutorService executor, Collection<? extends Callable<T>> tasks) Executes given tasks the same asExecutorService.invokeAll(Collection), but only if the executor is not shutdown and returns a list of Futures representing pending completion of the tasks.static ThreadPoolExecutornewFixedThreadPoolExecutor(int poolSize, String name) static velox.api.layer1.common.helper.PriorityThreadPoolExecutorstatic ThreadPoolExecutorSimilar toExecutors.newSingleThreadExecutor(), but limits threads lifetime and sets a namestatic ThreadPoolExecutorRespects priority of runnables if those are instances ofExecutorsHelper.PrioritizedRunnable, limits threads lifetime, sets a name.static ScheduledExecutorServicenewScheduledThreadPool(int corePoolSize, String name) static ThreadPoolExecutorSimilar toExecutors.newSingleThreadExecutor(), but sets a name and isn't wrapped in FinalizableDelegatedExecutorServicestatic ThreadPoolExecutornewSingleThreadExecutor(String name, Consumer<Boolean> queueEmptyCallback) Similar toExecutors.newSingleThreadExecutor(), but sets a name and isn't wrapped in FinalizableDelegatedExecutorServicestatic ThreadPoolExecutornewThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name) static ThreadPoolExecutornewThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name, BlockingQueue<Runnable> queue) static ThreadPoolExecutornewThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name, BlockingQueue<Runnable> queue, RejectedExecutionHandler handler) static ThreadPoolExecutornewThreadPoolExecutor(int corePoolSize, int maximumPoolSize, String name, Consumer<Boolean> queueEmptyCallback) static ThreadPoolExecutornewThreadPoolPriorityExecutor(int corePoolSize, int maximumPoolSize, String name) 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.static <T> Future<T>submitIfNotShutdown(ExecutorService executor, Callable<T> task)
-
Constructor Details
-
ExecutorsHelper
public ExecutorsHelper()
-
-
Method Details
-
newOnDemandSingleThreadExecutor
Similar toExecutors.newSingleThreadExecutor(), but limits threads lifetime and sets a name -
newOnDemandSingleThreadPriorityExecutor
Respects priority of runnables if those are instances ofExecutorsHelper.PrioritizedRunnable, limits threads lifetime, sets a name. Otherwise similar toExecutors.newSingleThreadExecutor() -
newSingleThreadExecutor
Similar toExecutors.newSingleThreadExecutor(), but sets a name and isn't wrapped in FinalizableDelegatedExecutorService -
newSingleThreadExecutor
public static ThreadPoolExecutor newSingleThreadExecutor(String name, Consumer<Boolean> queueEmptyCallback) Similar toExecutors.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
-
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
-
newOnDemandPriorityThreadPoolExecutor
public static velox.api.layer1.common.helper.PriorityThreadPoolExecutor newOnDemandPriorityThreadPoolExecutor(String name) -
executeIfNotShutdown
Executes the given command the same asExecutor.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 taskcommand- 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 aScheduledFuture<?>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- TheScheduledExecutorServiceto be used to schedule the task.command- TheRunnabletask to be scheduled.delay- The delay after which the command is to be executed.unit- TheTimeUnitof 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 asExecutorService.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 taskstasks- callable task to be executed- Returns:
- a list of Futures representing pending completion of the tasks, or empty list if the executor is shutdown
-
submitIfNotShutdown
- Returns:
- future or null if executor is shutdown
-