public final class Executors
extends java.lang.Object
Executor
s.Modifier and Type | Method and Description |
---|---|
static Executor |
from(java.util.concurrent.Executor jdkExecutor)
Creates a new
Executor from the provided jdkExecutor . |
static Executor |
from(java.util.concurrent.Executor jdkExecutor,
java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Creates a new
Executor using executor to execute immediate tasks and scheduler to
schedule delayed tasks. |
static Executor |
from(java.util.concurrent.Executor jdkExecutor,
java.util.concurrent.ScheduledExecutorService scheduledExecutorService,
boolean mayInterruptOnCancel)
Creates a new
Executor using executor to execute immediate tasks and scheduler to
schedule delayed tasks. |
static Executor |
from(java.util.concurrent.ExecutorService executorService)
Creates a new
Executor from the provided ExecutorService . |
static Executor |
from(java.util.concurrent.ExecutorService executorService,
boolean mayInterruptOnCancel)
Creates a new
Executor from the provided ExecutorService . |
static Executor |
from(java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Creates a new
Executor from the provided ScheduledExecutorService . |
static Executor |
from(java.util.concurrent.ScheduledExecutorService scheduledExecutorService,
boolean mayInterruptOnCancel)
Creates a new
Executor from the provided ScheduledExecutorService . |
static Executor |
immediate()
Returns an
Executor that executes all tasks submitted via Executor.execute(Runnable) immediately
by calling Runnable.run() on the calling thread. |
static Executor |
newCachedThreadExecutor()
Creates a new
Executor that creates as many threads as required but reuses threads when possible. |
static Executor |
newCachedThreadExecutor(java.util.concurrent.ThreadFactory threadFactory)
Creates a new
Executor that creates as many threads as required but reuses threads when possible. |
static Executor |
newFixedSizeExecutor(int size)
Creates a new
Executor that has a fixed number of threads as specified by the size . |
static Executor |
newFixedSizeExecutor(int size,
java.util.concurrent.ThreadFactory threadFactory)
Creates a new
Executor that has a fixed number of threads as specified by the size . |
public static Executor immediate()
Executor
that executes all tasks submitted via Executor.execute(Runnable)
immediately
by calling Runnable.run()
on the calling thread. Executor.schedule(Runnable, long, TimeUnit)
will
use a global scheduler.Executor
that executes all tasks submitted via Executor.execute(Runnable)
immediately on the calling thread.public static Executor newFixedSizeExecutor(int size)
Executor
that has a fixed number of threads as specified by the size
.public static Executor newFixedSizeExecutor(int size, java.util.concurrent.ThreadFactory threadFactory)
Executor
that has a fixed number of threads as specified by the size
.public static Executor newCachedThreadExecutor()
Executor
that creates as many threads as required but reuses threads when possible.Executor
.public static Executor newCachedThreadExecutor(java.util.concurrent.ThreadFactory threadFactory)
Executor
that creates as many threads as required but reuses threads when possible.threadFactory
- ThreadFactory
to use.Executor
.public static Executor from(java.util.concurrent.Executor jdkExecutor)
Executor
from the provided jdkExecutor
.
Delayed task execution will be delegated to a global scheduler, unless passed
Executor
is an instance of ScheduledExecutorService
.
Task execution will not honor cancellations unless passed Executor
is an instance of ExecutorService
.
Executor
implementations are expected to run long running (blocking) tasks which may
depend on other tasks submitted to the same Executor
instance.
In order to avoid deadlocks, it is generally a good idea to not allow task queuing in the
Executor
.jdkExecutor
- Executor
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
(if possible).Executor
that wraps the passed jdkExecutor
.public static Executor from(java.util.concurrent.ExecutorService executorService)
Executor
from the provided ExecutorService
.
Delayed task execution will be delegated to a global scheduler, unless passed ExecutorService
is an instance of ScheduledExecutorService
.
When a running task is cancelled, the thread running it will be interrupted.
For overriding this behavior use from(ExecutorService, boolean)
.
Executor
implementations are expected to run long running (blocking) tasks which may
depend on other tasks submitted to the same Executor
instance.
In order to avoid deadlocks, it is generally a good idea to not allow task queuing in the
Executor
.executorService
- ExecutorService
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
.Executor
that wraps the passed executorService
.public static Executor from(java.util.concurrent.ExecutorService executorService, boolean mayInterruptOnCancel)
Executor
from the provided ExecutorService
.
Delayed task execution will be delegated to a global scheduler, unless passed ExecutorService
is an instance of ScheduledExecutorService
.
Executor
implementations are expected to run long running (blocking) tasks which may
depend on other tasks submitted to the same Executor
instance.
In order to avoid deadlocks, it is generally a good idea to not allow task queuing in the
Executor
.executorService
- ExecutorService
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
.mayInterruptOnCancel
- If set to true
, when a task is cancelled, thread running the task will be
interrupted.Executor
that wraps the passed executorService
.public static Executor from(java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Executor
from the provided ScheduledExecutorService
.
When a running task is cancelled, the thread running it will be interrupted.
For overriding this behavior use from(ScheduledExecutorService, boolean)
.
Executor
implementations are expected to run long running (blocking) tasks which may
depend on other tasks submitted to the same Executor
instance.
In order to avoid deadlocks, it is generally a good idea to not allow task queuing in the
Executor
.scheduledExecutorService
- ScheduledExecutorService
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
.Executor
that wraps the passed scheduledExecutorService
.public static Executor from(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, boolean mayInterruptOnCancel)
Executor
from the provided ScheduledExecutorService
.
Executor
implementations are expected to run long running (blocking) tasks which may
depend on other tasks submitted to the same Executor
instance.
In order to avoid deadlocks, it is generally a good idea to not allow task queuing in the
Executor
.scheduledExecutorService
- ScheduledExecutorService
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
.mayInterruptOnCancel
- If set to true
, when a task is cancelled, thread running the task will be
interrupted.Executor
that wraps the passed scheduledExecutorService
.public static Executor from(java.util.concurrent.Executor jdkExecutor, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Executor
using executor
to execute immediate tasks and scheduler
to
schedule delayed tasks.
When a running task is cancelled, the thread running it will be interrupted.
For overriding this behavior use from(java.util.concurrent.Executor, ScheduledExecutorService, boolean)
.
Task execution will not honor cancellations unless passed Executor
is an instance of ExecutorService
.
Executor
implementations are expected to run long running (blocking) tasks which may
depend on other tasks submitted to the same Executor
instance.
In order to avoid deadlocks, it is generally a good idea to not allow task queuing in the
Executor
.jdkExecutor
- Executor
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
(if possible).scheduledExecutorService
- ScheduledExecutorService
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
.Executor
.public static Executor from(java.util.concurrent.Executor jdkExecutor, java.util.concurrent.ScheduledExecutorService scheduledExecutorService, boolean mayInterruptOnCancel)
Executor
using executor
to execute immediate tasks and scheduler
to
schedule delayed tasks.
Task execution will not honor cancellations unless passed Executor
is an instance of ExecutorService
.
Executor
implementations are expected to run long running (blocking) tasks which may
depend on other tasks submitted to the same Executor
instance.
In order to avoid deadlocks, it is generally a good idea to not allow task queuing in the
Executor
.jdkExecutor
- Executor
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
(if possible).scheduledExecutorService
- ScheduledExecutorService
to use for executing tasks.
The lifetime of this object is transferred to the return value. In other words AsyncCloseable.closeAsync()
will
call ExecutorService.shutdown()
.mayInterruptOnCancel
- If set to true
, when a task is cancelled, thread running the task will be
interrupted.Executor
.