Class ContextAwareExecutorService
- java.lang.Object
-
- nl.talsmasoftware.context.delegation.Wrapper<ExecutorService>
-
- nl.talsmasoftware.context.delegation.DelegatingExecutorService
-
- nl.talsmasoftware.context.delegation.CallMappingExecutorService
-
- nl.talsmasoftware.context.executors.ContextAwareExecutorService
-
- All Implemented Interfaces:
Executor
,ExecutorService
public class ContextAwareExecutorService extends CallMappingExecutorService
Executor service that wraps another executor service, making sure background tasks operates 'within' a context snapshot taken from the submitting thread.The executor service will make sure to close the reactivated snapshot again after the code in the task is finished, even if it throws an exception.
- Author:
- Sjoerd Talsma
-
-
Constructor Summary
Constructors Constructor Description ContextAwareExecutorService(ExecutorService delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <V> Callable<V>
map(Callable<V> callable)
This method maps any callable (before scheduling it) by taking a snapshot of the context in the scheduling thread and propagating this context into the executed callable by snapshot reactivation.-
Methods inherited from class nl.talsmasoftware.context.delegation.CallMappingExecutorService
wrap, wrap
-
Methods inherited from class nl.talsmasoftware.context.delegation.DelegatingExecutorService
awaitTermination, equals, execute, hashCode, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit, toString, wrap, wrapFutures, wrapTasks
-
Methods inherited from class nl.talsmasoftware.context.delegation.Wrapper
delegate, nonNullDelegate
-
-
-
-
Constructor Detail
-
ContextAwareExecutorService
public ContextAwareExecutorService(ExecutorService delegate)
-
-
Method Detail
-
map
protected <V> Callable<V> map(Callable<V> callable)
This method maps any callable (before scheduling it) by taking a snapshot of the context in the scheduling thread and propagating this context into the executed callable by snapshot reactivation.- Specified by:
map
in classCallMappingExecutorService
- Type Parameters:
V
- the actual return type of the callable object being scheduled.- Parameters:
callable
- The callable to be mapped.- Returns:
- A callable that will reactivate the scheduling thread context snapshot before executing.
-
-