Class ThreadContextExecutors
java.lang.Object
com.sap.cloud.sdk.cloudplatform.thread.ThreadContextExecutors
Convenience class, giving static access to the functionality of a
ThreadContextExecutorService, using a
configurable instance.
For example:
final Future<Try<Tenant>> tenant =
ThreadContextExecutors.submit(
// code that is executed within the ThreadContext created by DefaultThreadContextExecutorService
TenantAccessor::tryGetCurrentTenant);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAttach aThreadContextto the given command and execute it.static voidexecute(Runnable command, ThreadContext threadContext) Attach aThreadContextto the given command and execute it.static voidexecute(Runnable command, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given command and execute it.static ThreadContextExecutorServiceGet the unique executor of this class.static voidsetExecutor(ThreadContextExecutorService executor) Set the unique executor of this class or reset it if the given executor is null.static <T> Future<T>Attach aThreadContextto the given task and execute it.static <T> Future<T>submit(Callable<T> task, ThreadContext threadContext) Attach aThreadContextto the given task and execute it.static <T> Future<T>submit(Callable<T> task, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutorto the given task and execute it.
-
Constructor Details
-
ThreadContextExecutors
public ThreadContextExecutors()
-
-
Method Details
-
getExecutor
Get the unique executor of this class.- Returns:
- The unique customized executor instance.
-
setExecutor
Set the unique executor of this class or reset it if the given executor is null.- Parameters:
executor- the executor of this class
-
execute
Attach aThreadContextto the given command and execute it.- Parameters:
command- the runnable task- See Also:
-
execute
Attach aThreadContextto the given command and execute it.- Parameters:
command- the runnable taskthreadContext- theThreadContextto attach to the command- See Also:
-
execute
public static void execute(@Nonnull Runnable command, @Nonnull ThreadContextExecutor threadContextExecutor) 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 submit- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
@Nonnull public static <T> Future<T> submit(@Nonnull Callable<T> task, @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 task- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
@Nonnull public static <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:
-