public class ManagedExecutors
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
isCurrentThreadShutdown()
Utility method for checking the
isShutdown() value of the current
thread if it is a ManageableThread created from
ManagedThreadFactory.newThread() . |
static <V> java.util.concurrent.Callable<V> |
managedTask(java.util.concurrent.Callable<V> task,
ManagedTaskListener taskListener)
Returns a
Callable object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener when the task is submitted
to a ManagedExecutorService or a ManagedScheduledExecutorService . |
static <V> java.util.concurrent.Callable<V> |
managedTask(java.util.concurrent.Callable<V> task,
java.util.Map<java.lang.String,java.lang.String> executionProperties,
ManagedTaskListener taskListener)
Returns a
Callable object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener and to provide additional execution
properties when the task is submitted to a ManagedExecutorService or a
ManagedScheduledExecutorService . |
static java.lang.Runnable |
managedTask(java.lang.Runnable task,
ManagedTaskListener taskListener)
Returns a
Runnable object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener when the task is submitted
to a ManagedExecutorService or a ManagedScheduledExecutorService . |
static java.lang.Runnable |
managedTask(java.lang.Runnable task,
java.util.Map<java.lang.String,java.lang.String> executionProperties,
ManagedTaskListener taskListener)
Returns a
Runnable object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener and to provide additional execution
properties when the task is submitted to a ManagedExecutorService or a
ManagedScheduledExecutorService . |
public static boolean isCurrentThreadShutdown()
isShutdown()
value of the current
thread if it is a ManageableThread
created from
ManagedThreadFactory.newThread()
.isShutdown()
value if the current thread is a
ManageableThread
created by ManagedThreadFactory
, or
false if the current thread is not a ManageableThread
.public static java.lang.Runnable managedTask(java.lang.Runnable task, ManagedTaskListener taskListener) throws java.lang.IllegalArgumentException
Runnable
object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener
when the task is submitted
to a ManagedExecutorService
or a ManagedScheduledExecutorService
.
Example:
Runnable task = ...; ManagedTaskListener myTaskListener = ...; ManagedExecutorService executor = ...; Runnable taskWithListener = ManagedExecutors.managedTask(task, myTaskListener); executor.submit(taskWithListener);
task
- the task to have the given ManagedTaskListener associated withtaskListener
- (optional) the ManagedTaskListener
to receive
lifecycle events notification when the task is submitted. If task
implements ManagedTask
, and taskListener
is not
null
, the ManagedTaskListener
interface methods of the
task will not be called.java.lang.IllegalArgumentException
- if task
is null
public static java.lang.Runnable managedTask(java.lang.Runnable task, java.util.Map<java.lang.String,java.lang.String> executionProperties, ManagedTaskListener taskListener) throws java.lang.IllegalArgumentException
Runnable
object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener
and to provide additional execution
properties when the task is submitted to a ManagedExecutorService
or a
ManagedScheduledExecutorService
.task
- the task to have the given ManagedTaskListener associated withtaskListener
- (optional) the ManagedTaskListener
to receive
lifecycle events notification when the task is submitted. If task
implements ManagedTask
, and taskListener
is not
null
, the ManagedTaskListener
interface methods of the
task will not be called.executionProperties
- (optional) execution properties to provide additional hints
to ManagedExecutorService
or ManagedScheduledExecutorService
when the task is submitted.
If task
implements ManagedTask
with non-empty
execution properties, the Runnable
returned will contain the union
of the execution properties specified in the task
and the executionProperties
argument, with the latter taking precedence if the same property key is
specified in both.
After the method is called, further changes to the Map
object will not be reflected in the Runnable
returned by this method.java.lang.IllegalArgumentException
- if task
is null
public static <V> java.util.concurrent.Callable<V> managedTask(java.util.concurrent.Callable<V> task, ManagedTaskListener taskListener) throws java.lang.IllegalArgumentException
Callable
object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener
when the task is submitted
to a ManagedExecutorService
or a ManagedScheduledExecutorService
.task
- the task to have the given ManagedTaskListener associated withtaskListener
- (optional) the ManagedTaskListener
to receive
lifecycle events notification when the task is submitted. If task
implements ManagedTask
, and taskListener
is not
null
, the ManagedTaskListener
interface methods of the
task will not be called.java.lang.IllegalArgumentException
- if task
is null
public static <V> java.util.concurrent.Callable<V> managedTask(java.util.concurrent.Callable<V> task, java.util.Map<java.lang.String,java.lang.String> executionProperties, ManagedTaskListener taskListener) throws java.lang.IllegalArgumentException
Callable
object that also implements ManagedTask
interface so it can receive notification of lifecycle events with the
provided ManagedTaskListener
and to provide additional execution
properties when the task is submitted to a ManagedExecutorService
or a
ManagedScheduledExecutorService
.task
- the task to have the given ManagedTaskListener associated withtaskListener
- (optional) the ManagedTaskListener
to receive
lifecycle events notification when the task is submitted. If task
implements ManagedTask
, and taskListener
is not
null
, the ManagedTaskListener
interface methods of the
task will not be called.executionProperties
- (optional) execution properties to provide additional hints
to ManagedExecutorService
or ManagedScheduledExecutorService
when the task is submitted.
If task
implements ManagedTask
with non-empty
execution properties, the Runnable
returned will contain the union
of the execution properties specified in the task
and the executionProperties
argument, with the latter taking precedence if the same property key is
specified in both.
After the method is called, further changes to the Map
object will not be reflected in the Callable
returned by this method.java.lang.IllegalArgumentException
- if task
is null