Interface ThreadContextExecutorService
- All Superinterfaces:
Executor,ExecutorService
- All Known Implementing Classes:
DefaultThreadContextExecutorService
Allows the execution of
Runnable and Callable within a ThreadContext within a
ExecutorService.
The ThreadContext properties will be automatically propagated to the asynchronous task (either
Runnable or Callable) if the current Thread already contains a ThreadContext.
For example:
final DefaultThreadContextExecutorService executor =
DefaultThreadContextExecutorService.of(Executors.newCachedThreadPool());
final Future<Try<Tenant>> tenant =
executor.submit(
// code that is executed within the ThreadContext created by DefaultThreadContextExecutorService
TenantAccessor::tryGetCurrentTenant);
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(Runnable command, ThreadContext threadContext) Attach aThreadContextto the given command and execute it.voidexecute(Runnable command, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given command and execute it.Future<?>submit(Runnable task, ThreadContext threadContext) Attach aThreadContextto the given task and execute it.Future<?>submit(Runnable task, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given task and execute it.<T> Future<T>submit(Runnable task, T result, ThreadContext threadContext) Attach aThreadContextto the given task and execute it.<T> Future<T>submit(Runnable task, T result, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given task and execute it.<T> Future<T>submit(Callable<T> task, ThreadContext threadContext) Attach aThreadContextto the given task and execute it.<T> Future<T>submit(Callable<T> task, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given task and execute it.Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
Method Details
-
execute
Attach aThreadContextto the given command and execute it.- Parameters:
command- the runnable taskthreadContext- theThreadContextto attach to the command- See Also:
-
execute
Attach aThreadContextExecutorto the given command and execute it.- Parameters:
command- the runnable taskthreadContextExecutor- theThreadContextExecutorto attach to the command- See Also:
-
submit
Attach aThreadContextto the given task and execute it.- Type Parameters:
T- the type of the task's result- Parameters:
task- the task to submitthreadContext- theThreadContextto attach to the task- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
@Nonnull <T> Future<T> submit(@Nonnull Callable<T> task, @Nonnull ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given task and execute it.- Type Parameters:
T- the type of the task's result- Parameters:
task- the task to submitthreadContextExecutor- theThreadContextExecutorto attach to the task- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
@Nonnull <T> Future<T> submit(@Nonnull Runnable task, @Nonnull T result, @Nonnull ThreadContext threadContext) Attach aThreadContextto the given task and execute it.- Type Parameters:
T- the type of the task's result- Parameters:
task- the task to submitthreadContext- theThreadContextto attach to the taskresult- the result to return- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
@Nonnull <T> Future<T> submit(@Nonnull Runnable task, @Nonnull T result, @Nonnull ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given task and execute it.- Type Parameters:
T- the type of the task's result- Parameters:
task- the task to submitthreadContextExecutor- theThreadContextExecutorto attach to the taskresult- the result to return- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
Attach aThreadContextto the given task and execute it.- Parameters:
task- the task to submitthreadContext- theThreadContextto attach to the task- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
@Nonnull Future<?> submit(@Nonnull Runnable task, @Nonnull ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given task and execute it.- Parameters:
task- the task to submitthreadContextExecutor- theThreadContextExecutorto attach to the task- Returns:
- a Future representing pending completion of the task
- See Also:
-