Class ContextualExecutors
- Since:
- 5.0.0
- Author:
- James R. Perkins
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection
<? extends Callable<T>> callable
(Collection<? extends Callable<T>> tasks) Creates a new collection of callables which sets up the current context before each callable is executed.static <V> Callable
<V> Creates a new callable which sets up the current context before the callable is executed.static Executor
executor()
An executor which executes tasks in the current threadstatic Runnable
Creates a new runnable which sets up the current context before the runnable is executed.Creates a newContextualScheduledExecutorService
or wraps the defaultManagedScheduledExecutorService
in a Jakarta EE environment.scheduledThreadPool
(int poolSize, ThreadFactory threadFactory) Creates a newContextualScheduledExecutorService
or wraps the defaultManagedScheduledExecutorService
in a Jakarta EE environment.static ContextualExecutorService
Creates a newContextualExecutorService
or wraps the defaultManagedExecutorService
in a Jakarta EE environment.static ContextualExecutorService
wrap
(ExecutorService delegate) Wraps the executor service in contextual executor and is said to be managed.static ContextualExecutorService
wrap
(ExecutorService delegate, boolean managed) Wraps the executor service in contextual executor and is said to be managed.wrap
(ScheduledExecutorService delegate) Wraps the executor service in contextual executor and is said to be managed.wrap
(ScheduledExecutorService delegate, boolean managed) Wraps the executor service in contextual executor and is said to be managed.wrapOrLookup
(ScheduledExecutorService delegate) If the delegate is notnull
, it is wrapped.
-
Constructor Details
-
ContextualExecutors
public ContextualExecutors()
-
-
Method Details
-
executor
An executor which executes tasks in the current thread- Returns:
- a new contextual executor
-
threadPool
Creates a newContextualExecutorService
or wraps the defaultManagedExecutorService
in a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedExecutorService
, that executor is wrapped an said to be managed. If the default executor service cannot be found or if not being executed in a Jakarta EE container a new cached thread pool will be wrapped.In a Jakarta EE container the JNDI lookup name can be overridden with the
resteasy.async.executor.service.jndi
configuration property. By default the JNDI lookup name isjava:comp/DefaultManagedExecutorService
.- Returns:
- a new contextual executor
-
scheduledThreadPool
Creates a newContextualScheduledExecutorService
or wraps the defaultManagedScheduledExecutorService
in a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedScheduledExecutorService
, that executor is wrapped an said to be managed. If the default executor service cannot be found or if not being executed in a Jakarta EE container a new scheduled thread pool will be wrapped. The size of the thread pool is retrieved via theresteasy.async.timeout.scheduler.min.pool.size
context parameter. If not found1
is the default. The thread pool size is ignored in Jakarta EE environments.In a Jakarta EE container the JNDI lookup name can be overridden with the
resteasy.async.scheduled.executor.service.jndi
configuration property. By default the JNDI lookup name isjava:comp/DefaultManagedScheduledExecutorService
.- Returns:
- a new contextual executor
-
scheduledThreadPool
public static ContextualScheduledExecutorService scheduledThreadPool(int poolSize, ThreadFactory threadFactory) Creates a newContextualScheduledExecutorService
or wraps the defaultManagedScheduledExecutorService
in a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedScheduledExecutorService
, that executor is wrapped an said to be managed. If the default executor service cannot be found or if not being executed in a Jakarta EE container a new scheduled thread pool will be wrapped.In a Jakarta EE container the JNDI lookup name can be overridden with the
resteasy.async.scheduled.executor.service.jndi
configuration property. By default the JNDI lookup name isjava:comp/DefaultManagedScheduledExecutorService
.- Parameters:
poolSize
- the size of the pool to create, ignored in a Jakarta EE containerthreadFactory
- the thread factory to use if a new executor is created, ignored in a Jakarta EE container- Returns:
- a new contextual executor
-
wrap
Wraps the executor service in contextual executor and is said to be managed. You are responsible for the lifecycle of the delegate.The context is copied in before each invocation of the delegate, then reset after the thread is done executing.
- Parameters:
delegate
- the executor to wrap- Returns:
- a new contextual executor
-
wrap
Wraps the executor service in contextual executor and is said to be managed. You are responsible for the lifecycle of the delegate.The context is copied in before each invocation of the delegate, then reset after the thread is done executing.
- Parameters:
delegate
- the executor to wrapmanaged
-true
if the lifecycle is managed by another process- Returns:
- a new contextual executor
-
wrap
Wraps the executor service in contextual executor and is said to be managed. You are responsible for the lifecycle of the delegate.The context is copied in before each invocation of the delegate, then reset after the thread is done executing.
- Parameters:
delegate
- the executor to wrap- Returns:
- a new contextual executor
-
wrap
public static ContextualScheduledExecutorService wrap(ScheduledExecutorService delegate, boolean managed) Wraps the executor service in contextual executor and is said to be managed. You are responsible for the lifecycle of the delegate.The context is copied in before each invocation of the delegate, then reset after the thread is done executing.
- Parameters:
delegate
- the executor to wrapmanaged
-true
if the lifecycle is managed by another process- Returns:
- a new contextual executor
-
wrapOrLookup
If the delegate is notnull
, it is wrapped. If the delegate isnull
and this is a Jakarta EE environment an attempt will be made to look up the defaultManagedScheduledExecutorService
. If found the defaultManagedScheduledExecutorService
will be wrapped. Otherwise,null
will be returned.- Parameters:
delegate
- the delegate to wrap, which may benull
- Returns:
- a wrapped contextual executor or
null
if no executor was provided or could be found - See Also:
-
runnable
-
callable
-
callable
public static <T> Collection<? extends Callable<T>> callable(Collection<? extends Callable<T>> tasks) Creates a new collection of callables which sets up the current context before each callable is executed. Finally, resetting the context.- Type Parameters:
T
- the return type of the callable- Parameters:
tasks
- the callables to wrap- Returns:
- a collection of new contextual callables
- See Also:
-