Package io.servicetalk.concurrent.api
Class Executors
- java.lang.Object
-
- io.servicetalk.concurrent.api.Executors
-
public final class Executors extends java.lang.ObjectUtility methods to create variousExecutors.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Executorfrom(java.util.concurrent.Executor jdkExecutor)Creates a newExecutorfrom the providedjdkExecutor.static Executorfrom(java.util.concurrent.Executor jdkExecutor, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)Creates a newExecutorusingexecutorto execute immediate tasks andschedulerto schedule delayed tasks.static Executorfrom(java.util.concurrent.Executor jdkExecutor, java.util.concurrent.ScheduledExecutorService scheduledExecutorService, boolean mayInterruptOnCancel)Creates a newExecutorusingexecutorto execute immediate tasks andschedulerto schedule delayed tasks.static Executorfrom(java.util.concurrent.ExecutorService executorService)Creates a newExecutorfrom the providedExecutorService.static Executorfrom(java.util.concurrent.ExecutorService executorService, boolean mayInterruptOnCancel)Creates a newExecutorfrom the providedExecutorService.static Executorfrom(java.util.concurrent.ScheduledExecutorService scheduledExecutorService)Creates a newExecutorfrom the providedScheduledExecutorService.static Executorfrom(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, boolean mayInterruptOnCancel)Creates a newExecutorfrom the providedScheduledExecutorService.static Executorimmediate()Returns anExecutorthat executes all tasks submitted viaExecutor.execute(Runnable)immediately by callingRunnable.run()on the calling thread.static ExecutornewCachedThreadExecutor()Creates a newExecutorthat creates as many threads as required but reuses threads when possible.static ExecutornewCachedThreadExecutor(java.util.concurrent.ThreadFactory threadFactory)Creates a newExecutorthat creates as many threads as required but reuses threads when possible.static ExecutornewFixedSizeExecutor(int size)Creates a newExecutorthat has a fixed number of threads as specified by thesize.static ExecutornewFixedSizeExecutor(int size, java.util.concurrent.ThreadFactory threadFactory)Creates a newExecutorthat has a fixed number of threads as specified by thesize.
-
-
-
Method Detail
-
immediate
public static Executor immediate()
Returns anExecutorthat executes all tasks submitted viaExecutor.execute(Runnable)immediately by callingRunnable.run()on the calling thread.Executor.schedule(Runnable, long, TimeUnit)will use a global scheduler.- Returns:
- An
Executorthat executes all tasks submitted viaExecutor.execute(Runnable)immediately on the calling thread.
-
newFixedSizeExecutor
public static Executor newFixedSizeExecutor(int size)
Creates a newExecutorthat has a fixed number of threads as specified by thesize.
-
newFixedSizeExecutor
public static Executor newFixedSizeExecutor(int size, java.util.concurrent.ThreadFactory threadFactory)
Creates a newExecutorthat has a fixed number of threads as specified by thesize.
-
newCachedThreadExecutor
public static Executor newCachedThreadExecutor()
Creates a newExecutorthat creates as many threads as required but reuses threads when possible.- Returns:
- A new
Executor.
-
newCachedThreadExecutor
public static Executor newCachedThreadExecutor(java.util.concurrent.ThreadFactory threadFactory)
Creates a newExecutorthat creates as many threads as required but reuses threads when possible.- Parameters:
threadFactory-ThreadFactoryto use.- Returns:
- A new
Executor.
-
from
public static Executor from(java.util.concurrent.Executor jdkExecutor)
Creates a newExecutorfrom the providedjdkExecutor.Delayed task execution will be delegated to a global scheduler, unless passed
Executoris an instance ofScheduledExecutorService.Task execution will not honor cancellations unless passed
Executoris an instance ofExecutorService.Long running tasks
Executorimplementations are expected to run long running (blocking) tasks which may depend on other tasks submitted to the sameExecutorinstance. In order to avoid deadlocks, it is generally a good idea to not allow task queuing in theExecutor.- Parameters:
jdkExecutor-Executorto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown()(if possible).- Returns:
Executorthat wraps the passedjdkExecutor.
-
from
public static Executor from(java.util.concurrent.ExecutorService executorService)
Creates a newExecutorfrom the providedExecutorService.Delayed task execution will be delegated to a global scheduler, unless passed
ExecutorServiceis an instance ofScheduledExecutorService.When a running task is cancelled, the thread running it will be interrupted. For overriding this behavior use
from(ExecutorService, boolean).Long running tasks
Executorimplementations are expected to run long running (blocking) tasks which may depend on other tasks submitted to the sameExecutorinstance. In order to avoid deadlocks, it is generally a good idea to not allow task queuing in theExecutor.- Parameters:
executorService-ExecutorServiceto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown().- Returns:
Executorthat wraps the passedexecutorService.
-
from
public static Executor from(java.util.concurrent.ExecutorService executorService, boolean mayInterruptOnCancel)
Creates a newExecutorfrom the providedExecutorService. Delayed task execution will be delegated to a global scheduler, unless passedExecutorServiceis an instance ofScheduledExecutorService.Long running tasks
Executorimplementations are expected to run long running (blocking) tasks which may depend on other tasks submitted to the sameExecutorinstance. In order to avoid deadlocks, it is generally a good idea to not allow task queuing in theExecutor.- Parameters:
executorService-ExecutorServiceto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown().mayInterruptOnCancel- If set totrue, when a task is cancelled, thread running the task will be interrupted.- Returns:
Executorthat wraps the passedexecutorService.
-
from
public static Executor from(java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Creates a newExecutorfrom the providedScheduledExecutorService. When a running task is cancelled, the thread running it will be interrupted. For overriding this behavior usefrom(ScheduledExecutorService, boolean).Long running tasks
Executorimplementations are expected to run long running (blocking) tasks which may depend on other tasks submitted to the sameExecutorinstance. In order to avoid deadlocks, it is generally a good idea to not allow task queuing in theExecutor.- Parameters:
scheduledExecutorService-ScheduledExecutorServiceto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown().- Returns:
Executorthat wraps the passedscheduledExecutorService.
-
from
public static Executor from(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, boolean mayInterruptOnCancel)
Creates a newExecutorfrom the providedScheduledExecutorService.Long running tasks
Executorimplementations are expected to run long running (blocking) tasks which may depend on other tasks submitted to the sameExecutorinstance. In order to avoid deadlocks, it is generally a good idea to not allow task queuing in theExecutor.- Parameters:
scheduledExecutorService-ScheduledExecutorServiceto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown().mayInterruptOnCancel- If set totrue, when a task is cancelled, thread running the task will be interrupted.- Returns:
Executorthat wraps the passedscheduledExecutorService.
-
from
public static Executor from(java.util.concurrent.Executor jdkExecutor, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Creates a newExecutorusingexecutorto execute immediate tasks andschedulerto schedule delayed tasks. When a running task is cancelled, the thread running it will be interrupted. For overriding this behavior usefrom(java.util.concurrent.Executor, ScheduledExecutorService, boolean). Task execution will not honor cancellations unless passedExecutoris an instance ofExecutorService.Long running tasks
Executorimplementations are expected to run long running (blocking) tasks which may depend on other tasks submitted to the sameExecutorinstance. In order to avoid deadlocks, it is generally a good idea to not allow task queuing in theExecutor.- Parameters:
jdkExecutor-Executorto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown()(if possible).scheduledExecutorService-ScheduledExecutorServiceto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown().- Returns:
- A new
Executor.
-
from
public static Executor from(java.util.concurrent.Executor jdkExecutor, java.util.concurrent.ScheduledExecutorService scheduledExecutorService, boolean mayInterruptOnCancel)
Creates a newExecutorusingexecutorto execute immediate tasks andschedulerto schedule delayed tasks. Task execution will not honor cancellations unless passedExecutoris an instance ofExecutorService.Long running tasks
Executorimplementations are expected to run long running (blocking) tasks which may depend on other tasks submitted to the sameExecutorinstance. In order to avoid deadlocks, it is generally a good idea to not allow task queuing in theExecutor.- Parameters:
jdkExecutor-Executorto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown()(if possible).scheduledExecutorService-ScheduledExecutorServiceto use for executing tasks. The lifetime of this object is transferred to the return value. In other wordsAsyncCloseable.closeAsync()will callExecutorService.shutdown().mayInterruptOnCancel- If set totrue, when a task is cancelled, thread running the task will be interrupted.- Returns:
- A new
Executor.
-
-