| Modifier and Type | Method and Description |
|---|---|
static Optional<Context> |
context()
Get context registry associated with current thread.
|
static <T> T |
runInContext(Context context,
Callable<T> callable)
Run the callable in the provided context.
|
static void |
runInContext(Context context,
Runnable runnable)
Run the runnable in the provided context.
|
static <T> T |
runInContextWithThrow(Context context,
Callable<T> callable)
Run the callable in the provided context throwing any exception from
its execution.
|
static ExecutorService |
wrap(ExecutorService toWrap)
Wrap an executor service to correctly propagate context to its threads.
|
static ScheduledExecutorService |
wrap(ScheduledExecutorService toWrap)
Wrap a scheduled executor service to correctly propagate context to its threads.
|
public static Optional<Context> context()
public static ExecutorService wrap(ExecutorService toWrap)
toWrap - executor servicepublic static ScheduledExecutorService wrap(ScheduledExecutorService toWrap)
toWrap - executor servicepublic static void runInContext(Context context, Runnable runnable)
context() to retrieve the context.context - context to run inrunnable - runnable to execute in contextpublic static <T> T runInContext(Context context, Callable<T> callable)
context() to retrieve the context.T - return type of the callablecontext - context to run incallable - callable to execute in contextRuntimeException - in case the Callable.call() threw a
runtime exceptionpublic static <T> T runInContextWithThrow(Context context, Callable<T> callable) throws Exception
context() to retrieve
the context.T - return type of the callablecontext - context to run incallable - callable to execute in contextException - If thrown in Callable.call()Copyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.