Class WorkflowThreadLocal<T>

java.lang.Object
io.temporal.workflow.WorkflowThreadLocal<T>

public final class WorkflowThreadLocal<T> extends Object
ThreadLocal analog for workflow code.
  • Constructor Details

    • WorkflowThreadLocal

      public WorkflowThreadLocal()
  • Method Details

    • withInitial

      @Deprecated public static <S> WorkflowThreadLocal<S> withInitial(Supplier<? extends S> supplier)
      Deprecated.
      Because the non-caching behavior of this API is typically not desirable, it's recommend to use withCachedInitial(Supplier) instead.
      Create an instance that returns the value returned by the given Supplier when set(Object) has not yet been called in the thread. Note that the value returned by the Supplier is not stored in the WorkflowThreadLocal implicitly; repeatedly calling get() will always re-execute the Supplier until you call set(Object) for the first time. This differs from the behavior of ThreadLocal. If you want the value returned by the Supplier to be stored in the WorkflowThreadLocal, which matches the behavior of ThreadLocal, use withCachedInitial(Supplier) instead.
      Type Parameters:
      S - The type stored in the WorkflowThreadLocal.
      Parameters:
      supplier - Callback that will be executed whenever get() is called, until set(Object) is called for the first time.
      Returns:
      A WorkflowThreadLocal instance.
    • withCachedInitial

      public static <S> WorkflowThreadLocal<S> withCachedInitial(Supplier<? extends S> supplier)
      Create an instance that returns the value returned by the given Supplier when set(Object) has not yet been called in the Workflow, and then stores the returned value inside the WorkflowThreadLocal.
      Type Parameters:
      S - The type stored in the WorkflowThreadLocal.
      Parameters:
      supplier - Callback that will be executed when get() is called for the first time, if set(Object) has not already been called.
      Returns:
      A WorkflowThreadLocal instance.
    • get

      public T get()
    • set

      public void set(T value)