Package io.temporal.workflow
Class WorkflowThreadLocal<T>
- java.lang.Object
-
- io.temporal.workflow.WorkflowThreadLocal<T>
-
public final class WorkflowThreadLocal<T> extends java.lang.ObjectThreadLocalanalog for workflow code.
-
-
Constructor Summary
Constructors Constructor Description WorkflowThreadLocal()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Tget()voidset(T value)static <S> WorkflowThreadLocal<S>withCachedInitial(java.util.function.Supplier<? extends S> supplier)Create an instance that returns the value returned by the givenSupplierwhen#set(S)has not yet been called in the Workflow, and then stores the returned value inside theWorkflowThreadLocal.static <S> WorkflowThreadLocal<S>withInitial(java.util.function.Supplier<? extends S> supplier)Deprecated.Because the non-caching behavior of this API is typically not desirable, it's recommend to usewithCachedInitial(Supplier)instead.
-
-
-
Method Detail
-
withInitial
@Deprecated public static <S> WorkflowThreadLocal<S> withInitial(java.util.function.Supplier<? extends S> supplier)
Deprecated.Because the non-caching behavior of this API is typically not desirable, it's recommend to usewithCachedInitial(Supplier)instead.Create an instance that returns the value returned by the givenSupplierwhen#set(S)has not yet been called in the thread. Note that the value returned by theSupplieris not stored in theWorkflowThreadLocalimplicitly; repeatedly callingget()will always re-execute theSupplieruntil you call#set(S)for the first time. This differs from the behavior ofThreadLocal. If you want the value returned by theSupplierto be stored in theWorkflowThreadLocal, which matches the behavior ofThreadLocal, usewithCachedInitial(Supplier)instead.- Type Parameters:
S- The type stored in theWorkflowThreadLocal.- Parameters:
supplier- Callback that will be executed wheneverget()is called, until#set(S)is called for the first time.- Returns:
- A
WorkflowThreadLocalinstance.
-
withCachedInitial
public static <S> WorkflowThreadLocal<S> withCachedInitial(java.util.function.Supplier<? extends S> supplier)
Create an instance that returns the value returned by the givenSupplierwhen#set(S)has not yet been called in the Workflow, and then stores the returned value inside theWorkflowThreadLocal.- Type Parameters:
S- The type stored in theWorkflowThreadLocal.- Parameters:
supplier- Callback that will be executed whenget()is called for the first time, if#set(S)has not already been called.- Returns:
- A
WorkflowThreadLocalinstance.
-
get
public T get()
-
set
public void set(T value)
-
-