- java.lang.Object
-
- jakarta.enterprise.concurrent.ManagedExecutors
-
public final class ManagedExecutors extends java.lang.ObjectUtility methods for classes defined in this package.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classManagedExecutors.Adapter(package private) static classManagedExecutors.CallableAdapter<V>Adapter for Callable to include ManagedTask interface methods.(package private) static classManagedExecutors.RunnableAdapterAdapter for Runnable to include ManagedTask interface methods.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringNULL_TASK_ERROR_MSGError message for null tasks.
-
Constructor Summary
Constructors Modifier Constructor Description privateManagedExecutors()Not suppose to create instances of this class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisCurrentThreadShutdown()Utility method for checking theisShutdown()value of the current thread if it is aManageableThreadcreated fromManagedThreadFactory.newThread().static java.lang.RunnablemanagedTask(java.lang.Runnable task, ManagedTaskListener taskListener)Returns aRunnableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerwhen the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.static java.lang.RunnablemanagedTask(java.lang.Runnable task, java.util.Map<java.lang.String,java.lang.String> executionProperties, ManagedTaskListener taskListener)Returns aRunnableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerand to provide additional execution properties when the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.static <V> java.util.concurrent.Callable<V>managedTask(java.util.concurrent.Callable<V> task, ManagedTaskListener taskListener)Returns aCallableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerwhen the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.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 aCallableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerand to provide additional execution properties when the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.
-
-
-
Field Detail
-
NULL_TASK_ERROR_MSG
static final java.lang.String NULL_TASK_ERROR_MSG
Error message for null tasks.- See Also:
- Constant Field Values
-
-
Method Detail
-
isCurrentThreadShutdown
public static boolean isCurrentThreadShutdown()
Utility method for checking theisShutdown()value of the current thread if it is aManageableThreadcreated fromManagedThreadFactory.newThread().- Returns:
- Returns the
isShutdown()value if the current thread is aManageableThreadcreated byManagedThreadFactory, or false if the current thread is not aManageableThread.
-
managedTask
public static java.lang.Runnable managedTask(java.lang.Runnable task, ManagedTaskListener taskListener) throws java.lang.IllegalArgumentExceptionReturns aRunnableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerwhen the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.Example:
Runnable task = ...; ManagedTaskListener myTaskListener = ...; ManagedExecutorService executor = ...; Runnable taskWithListener = ManagedExecutors.managedTask(task, myTaskListener); executor.submit(taskWithListener);
- Parameters:
task- the task to have the given ManagedTaskListener associated withtaskListener- (optional) theManagedTaskListenerto receive lifecycle events notification when the task is submitted. IftaskimplementsManagedTask, andtaskListeneris notnull, theManagedTaskListenerinterface methods of the task will not be called.- Returns:
- a Runnable object
- Throws:
java.lang.IllegalArgumentException- iftaskisnull
-
managedTask
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.IllegalArgumentExceptionReturns aRunnableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerand to provide additional execution properties when the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.- Parameters:
task- the task to have the given ManagedTaskListener associated withtaskListener- (optional) theManagedTaskListenerto receive lifecycle events notification when the task is submitted. IftaskimplementsManagedTask, andtaskListeneris notnull, theManagedTaskListenerinterface methods of the task will not be called.executionProperties- (optional) execution properties to provide additional hints toManagedExecutorServiceorManagedScheduledExecutorServicewhen the task is submitted. IftaskimplementsManagedTaskwith non-empty execution properties, theRunnablereturned will contain the union of the execution properties specified in thetaskand theexecutionPropertiesargument, with the latter taking precedence if the same property key is specified in both. After the method is called, further changes to theMapobject will not be reflected in theRunnablereturned by this method.- Returns:
- a Runnable object
- Throws:
java.lang.IllegalArgumentException- iftaskisnull
-
managedTask
public static <V> java.util.concurrent.Callable<V> managedTask(java.util.concurrent.Callable<V> task, ManagedTaskListener taskListener) throws java.lang.IllegalArgumentExceptionReturns aCallableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerwhen the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.- Type Parameters:
V- the return type of the Callable- Parameters:
task- the task to have the given ManagedTaskListener associated withtaskListener- (optional) theManagedTaskListenerto receive lifecycle events notification when the task is submitted. IftaskimplementsManagedTask, andtaskListeneris notnull, theManagedTaskListenerinterface methods of the task will not be called.- Returns:
- a Callable object
- Throws:
java.lang.IllegalArgumentException- iftaskisnull
-
managedTask
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.IllegalArgumentExceptionReturns aCallableobject that also implementsManagedTaskinterface so it can receive notification of lifecycle events with the providedManagedTaskListenerand to provide additional execution properties when the task is submitted to aManagedExecutorServiceor aManagedScheduledExecutorService.- Type Parameters:
V- the result type of the Callable- Parameters:
task- the task to have the given ManagedTaskListener associated withtaskListener- (optional) theManagedTaskListenerto receive lifecycle events notification when the task is submitted. IftaskimplementsManagedTask, andtaskListeneris notnull, theManagedTaskListenerinterface methods of the task will not be called.executionProperties- (optional) execution properties to provide additional hints toManagedExecutorServiceorManagedScheduledExecutorServicewhen the task is submitted. IftaskimplementsManagedTaskwith non-empty execution properties, theRunnablereturned will contain the union of the execution properties specified in thetaskand theexecutionPropertiesargument, with the latter taking precedence if the same property key is specified in both. After the method is called, further changes to theMapobject will not be reflected in theCallablereturned by this method.- Returns:
- a Callable object
- Throws:
java.lang.IllegalArgumentException- iftaskisnull
-
-