public final class SharedTaskContextHolder extends Object
Modifier and Type | Method and Description |
---|---|
static SharedTaskContext |
get()
Getter for #sharedTaskAbortStrategy.
|
static String |
getTaskId()
Return the task id for the current thread's task.
|
static void |
register(SharedTaskContext sharedTaskContext)
Initialize the
SharedTaskContextHolder with the sharedTaskContext . |
static void |
remove()
Removes the current
SharedTaskContext from the ThreadLocal store. |
static void |
setTaskAbortStrategy(TaskAbortStrategy taskAbortStrategy)
Set the current thread's
taskAbortStrategy . |
public static void register(SharedTaskContext sharedTaskContext)
SharedTaskContextHolder
with the sharedTaskContext
.
By registering the sharedTaskContext
the strategy is made available for other code within the executing thread. This
allows the guard task to abort the task being executed without knowing how.
The task itself is responsible to register a TaskAbortStrategy
in the sharedTaskContext
. This can be done by
calling the setTaskAbortStrategy(TaskAbortStrategy)
.
As an example, see the HawaiiHttpComponentsClientHttpRequestFactory
.
sharedTaskContext
- the shared strategy to hold for the current thread.public static void setTaskAbortStrategy(TaskAbortStrategy taskAbortStrategy)
taskAbortStrategy
.
This sets the taskAbortStrategy
into the thread's SharedTaskContext
.
taskAbortStrategy
- The strategy to set.public static SharedTaskContext get()
public static String getTaskId()
SharedTaskContext.getTaskId()
.public static void remove()
SharedTaskContext
from the ThreadLocal store.