Class ContextualExecutors
- java.lang.Object
-
- org.jboss.resteasy.concurrent.ContextualExecutors
-
public class ContextualExecutors extends Object
A utility to create and/or wrap executors in a contextual executor.- Since:
- 5.0.0
- Author:
- James R. Perkins
- See Also:
ContextualExecutorService,ContextualScheduledExecutorService,Executor
-
-
Constructor Summary
Constructors Constructor Description ContextualExecutors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static <V> Callable<V>callable(Callable<V> task)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 threadstatic Runnablerunnable(Runnable task)Creates a new runnable which sets up the current context before the runnable is executed.static ContextualScheduledExecutorServicescheduledThreadPool()Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.static ContextualScheduledExecutorServicescheduledThreadPool(int poolSize, ThreadFactory threadFactory)Creates a newContextualScheduledExecutorServiceor wraps the defaultManagedScheduledExecutorServicein a Jakarta EE environment.static ContextualExecutorServicethreadPool()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.static ContextualScheduledExecutorServicewrap(ScheduledExecutorService delegate)Wraps the executor service in contextual executor and is said to be managed.static ContextualScheduledExecutorServicewrap(ScheduledExecutorService delegate, boolean managed)Wraps the executor service in contextual executor and is said to be managed.static ContextualScheduledExecutorServicewrapOrLookup(ScheduledExecutorService delegate)If the delegate is notnull, it is wrapped.
-
-
-
Method Detail
-
executor
public static Executor executor()
An executor which executes tasks in the current thread- Returns:
- a new contextual executor
-
threadPool
public static ContextualExecutorService 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 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.jndiconfiguration property. By default the JNDI lookup name isjava:comp/DefaultManagedExecutorService.- Returns:
- a new contextual executor
-
scheduledThreadPool
public static ContextualScheduledExecutorService 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 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.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
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 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.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
-
wrap
public static ContextualExecutorService wrap(ExecutorService delegate)
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 ContextualExecutorService wrap(ExecutorService 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
-
wrap
public static ContextualScheduledExecutorService wrap(ScheduledExecutorService delegate)
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
public static ContextualScheduledExecutorService wrapOrLookup(ScheduledExecutorService delegate)
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:
wrap(ScheduledExecutorService)
-
runnable
public static Runnable runnable(Runnable task)
Creates a new runnable which sets up the current context before the runnable is executed. Finally, resetting the context.- Parameters:
task- the runnable to wrap- Returns:
- a new contextual runnable
-
callable
public static <V> Callable<V> callable(Callable<V> task)
Creates a new callable which sets up the current context before the callable is executed. Finally, resetting the context.- Type Parameters:
V- the return type- Parameters:
task- the callable to wrap- Returns:
- a new contextual 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:
callable(Callable)
-
-