Class ContextualExecutors
- Since:
- 5.0.0
- Author:
- James R. Perkins
- See Also:
-
Constructor Summary
Constructors -
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 Executorexecutor()An executor which executes tasks in the current threadCreates a newContextualScheduledExecutorServicebased on aScheduledThreadPoolExecutor.static ContextualExecutorServiceCreates a newContextualExecutorServicebased on aThreadPoolExecutor.static RunnableCreates a new runnable which sets up the current context before the runnable is executed.Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.scheduledThreadPool(boolean useDeployment) Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.scheduledThreadPool(int poolSize, ThreadFactory threadFactory) Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.static ContextualExecutorServiceCreates a newContextualExecutorServiceor wraps the defaultManagedExecutorServicein a Jakarta EE environment.static ContextualExecutorServicethreadPool(boolean useDeployment) Creates a newContextualExecutorServiceor wraps the defaultManagedExecutorServicein a Jakarta EE environment.static ContextualExecutorServicewrap(ExecutorService delegate) Wraps the executor service in contextual executor and is said to be managed.static ContextualExecutorServicewrap(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 newContextualExecutorServiceor wraps the defaultManagedExecutorServicein a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedExecutorService, that executor is wrapped and 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.jndiconfiguration property. By default, the JNDI lookup name isjava:comp/DefaultManagedExecutorService.- Returns:
- a new contextual executor
-
threadPool
Creates a newContextualExecutorServiceor wraps the defaultManagedExecutorServicein a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedExecutorService, that executor is wrapped and 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.jndiconfiguration property. By default, the JNDI lookup name isjava:comp/DefaultManagedExecutorService.- Parameters:
useDeployment-trueto use the deployment's executor if available,falseto always create a new unmanaged executor- Returns:
- a new contextual executor
-
newThreadPool
Creates a newContextualExecutorServicebased on aThreadPoolExecutor. The pool size can be overridden with thedev.resteasy.concurrent.core.pool.sizeconfiguration property.- Returns:
- a new contextual executor
-
scheduledThreadPool
Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedScheduledExecutorService, that executor is wrapped and 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.sizecontext parameter. If not found1is 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.jndiconfiguration property. By default the JNDI lookup name isjava:comp/DefaultManagedScheduledExecutorService.- Returns:
- a new contextual executor
-
scheduledThreadPool
Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedScheduledExecutorService, that executor is wrapped and 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.sizecontext parameter. If not found1is 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.jndiconfiguration property. By default the JNDI lookup name isjava:comp/DefaultManagedScheduledExecutorService.- Parameters:
useDeployment-trueto use the deployment's executor if available,falseto always create a new unmanaged executor- Returns:
- a new contextual executor
-
scheduledThreadPool
public static ContextualScheduledExecutorService scheduledThreadPool(int poolSize, ThreadFactory threadFactory) Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.If executed in a Jakarta EE container which includes a default
ManagedScheduledExecutorService, that executor is wrapped and 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.jndiconfiguration 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
-
newScheduledThreadPool
Creates a newContextualScheduledExecutorServicebased on aScheduledThreadPoolExecutor. The pool size can be overridden with theresteasy.async.timeout.scheduler.min.pool.sizeconfiguration property.- 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-trueif 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-trueif the lifecycle is managed by another process- Returns:
- a new contextual executor
-
wrapOrLookup
If the delegate is notnull, it is wrapped. If the delegate isnulland this is a Jakarta EE environment an attempt will be made to look up the defaultManagedScheduledExecutorService. If found the defaultManagedScheduledExecutorServicewill be wrapped. Otherwise,nullwill be returned.- Parameters:
delegate- the delegate to wrap, which may benull- Returns:
- a wrapped contextual executor or
nullif 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:
-