public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T>
TransmittableThreadLocal
can transmit value from the thread of submitting task to the thread of executing task.
Note: this class extends InheritableThreadLocal
,
so TransmittableThreadLocal
first is a InheritableThreadLocal
.
TtlRunnable
,
TtlCallable
Modifier and Type | Class and Description |
---|---|
static class |
TransmittableThreadLocal.Transmitter
TransmittableThreadLocal.Transmitter transmit all TransmittableThreadLocal of current thread to
any other thread by static method TransmittableThreadLocal.Transmitter.capture() => TransmittableThreadLocal.Transmitter.replay(Object) => TransmittableThreadLocal.Transmitter.restore(Object) (aka CRR operation). |
Constructor and Description |
---|
TransmittableThreadLocal() |
Modifier and Type | Method and Description |
---|---|
protected void |
afterExecute()
Callback method after task object(
TtlRunnable /TtlCallable ) execute. |
protected void |
beforeExecute()
Callback method before task object(
TtlRunnable /TtlCallable ) execute. |
protected T |
copy(T parentValue)
Computes the value for this transmittable thread-local variable
as a function of the source thread's value at the time the task
Object is created.
|
T |
get() |
void |
remove() |
void |
set(T value) |
childValue
initialValue, withInitial
protected T copy(T parentValue)
TtlRunnable
or
TtlCallable
when it create, before the task is started.
This method merely returns reference of its source thread value, and should be overridden if a different behavior is desired.
protected void beforeExecute()
TtlRunnable
/TtlCallable
) execute.
Default behavior is do nothing, and should be overridden if a different behavior is desired.
Do not throw any exception, just ignored.
protected void afterExecute()
TtlRunnable
/TtlCallable
) execute.
Default behavior is do nothing, and should be overridden if a different behavior is desired.
Do not throw any exception, just ignored.
public final T get()
get
in class ThreadLocal<T>
public final void set(T value)
set
in class ThreadLocal<T>
public final void remove()
remove
in class ThreadLocal<T>
Copyright © 2013–2018 Alibaba. All rights reserved.