docs/developer-guide-en.md
TTL transmittanceTransmittableThreadLocal.Transmitter to capture all TTL values of current thread and replay them in another thread.
There are following methodsοΌ
capture: capture all TTL values in current threadreplay: replay the captured TTL values in the current thread, and return the backup TTL values before replayrestore: restore TTL values before replaySample codeοΌ
// ===========================================================================
// Thread A
// ===========================================================================
TransmittableThreadLocal<String> context = new TransmittableThreadLocal<String>();
context.set("value-set-in-parent");
// 1. capture all TTL values in current thread
final Object captured = TransmittableThreadLocal.Transmitter.capture();
// ===========================================================================
// Thread B
// ===========================================================================
// 2. replay the captured TTL values in current thread, and return the backup TTL values before replay
final Object backup = TransmittableThreadLocal.Transmitter.replay(captured);
try {
// Your biz code, you can get the TTL value from here
String value = context.get();
...
} finally {
// 3. restore TTL values before replay
TransmittableThreadLocal.Transmitter.restore(backup);
}
TransmittableThreadLocal.Transmitter, see its Javadoc.TTL transmittance, see TtlRunnable.java and TtlCallable.java.JDK core classesJava AgentJavassistMaven Shade plugin