Package jakarta.enterprise.concurrent
Class ManagedExecutors
- java.lang.Object
-
- jakarta.enterprise.concurrent.ManagedExecutors
-
public final class ManagedExecutors extends Object
Utility methods for classes defined in this package.- Since:
- 1.0
-
-
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 RunnablemanagedTask(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 RunnablemanagedTask(Runnable task, Map<String,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> Callable<V>managedTask(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> Callable<V>managedTask(Callable<V> task, Map<String,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.
-
-
-
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 Runnable managedTask(Runnable task, ManagedTaskListener taskListener) throws IllegalArgumentException
Returns 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:
IllegalArgumentException- iftaskisnull
-
managedTask
public static Runnable managedTask(Runnable task, Map<String,String> executionProperties, ManagedTaskListener taskListener) throws IllegalArgumentException
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.- 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:
IllegalArgumentException- iftaskisnull
-
managedTask
public static <V> Callable<V> managedTask(Callable<V> task, ManagedTaskListener taskListener) throws IllegalArgumentException
Returns 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:
IllegalArgumentException- iftaskisnull
-
managedTask
public static <V> Callable<V> managedTask(Callable<V> task, Map<String,String> executionProperties, ManagedTaskListener taskListener) throws IllegalArgumentException
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.- 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:
IllegalArgumentException- iftaskisnull
-
-