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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Attach aThreadContext
to the given command and execute it.static void
execute
(Runnable command, ThreadContext threadContext) Attach aThreadContext
to the given command and execute it.static void
execute
(Runnable command, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutor
to the given command and execute it.static ThreadContextExecutorService
Get the unique executor of this class.static void
setExecutor
(ThreadContextExecutorService executor) Set the unique executor of this class or reset it if the given executor is null.static <T> Future<T>
Attach aThreadContext
to the given task and execute it.static <T> Future<T>
submit
(Callable<T> task, ThreadContext threadContext) Attach aThreadContext
to the given task and execute it.static <T> Future<T>
submit
(Callable<T> task, ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutor
to 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 aThreadContext
to the given command and execute it.- Parameters:
command
- the runnable task- See Also:
-
execute
Attach aThreadContext
to the given command and execute it.- Parameters:
command
- the runnable taskthreadContext
- theThreadContext
to attach to the command- See Also:
-
execute
public static void execute(@Nonnull Runnable command, @Nonnull ThreadContextExecutor threadContextExecutor) Attach aThreadContextExecutor
to the given command and execute it.- Parameters:
command
- the runnable taskthreadContextExecutor
- theThreadContextExecutor
to attach to the command- See Also:
-
submit
Attach aThreadContext
to 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 aThreadContext
to the given task and execute it.- Type Parameters:
T
- the type of the task's result- Parameters:
task
- the task to submitthreadContext
- theThreadContext
to 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 aThreadContextExecutor
to the given task and execute it.- Type Parameters:
T
- the type of the task's result- Parameters:
task
- the task to submitthreadContextExecutor
- theThreadContextExecutor
to attach to the task- Returns:
- a Future representing pending completion of the task
- See Also:
-