• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #165

pending completion
#165

push

github-actions

web-flow
Allow Data Converter code to escape deadlock detection (#1723)

Issue #1301

116 of 116 new or added lines in 5 files covered. (100.0%)

17121 of 20963 relevant lines covered (81.67%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.57
/temporal-sdk/src/main/java/io/temporal/workflow/unsafe/WorkflowUnsafe.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.workflow.unsafe;
22

23
import io.temporal.internal.sync.WorkflowInternal;
24
import io.temporal.workflow.Functions;
25

26
/**
27
 * While {@link io.temporal.workflow.Workflow} contains methods exposing the main Temporal Workflow
28
 * API that is safe to use by majority of our users, this class contains the part of the Workflow
29
 * API that is discouraged to be used without careful consideration. While APIs in this class may be
30
 * required for some legitimate scenarios, most users shouldn't be using them. Relying on these
31
 * methods without careful consideration and understanding of limitations of each method may lead to
32
 * an unexpected behavior and mistakes.
33
 *
34
 * <p>Please reference a documentation for each specific method for more context why this method is
35
 * considered unsafe to be a part of the main Workflow API.
36
 */
37
public final class WorkflowUnsafe {
38

39
  /**
40
   * <b>Warning!</b> <br>
41
   * The only reasonable usage for this method is writing a library code that has to be used in both
42
   * workflow and non-workflow code (like an Activity or non-Temporal codebase). This usage is
43
   * generally discouraged, because mixing of workflow and non-workflow code is error-prone, because
44
   * workflow code requires considerations for determinism. Writing shared code that is designed to
45
   * be called from both workflow and non-workflow context may lead to leaking of the code not
46
   * written with Workflow limitations in mind into Workflow method implementation leading to
47
   * non-deterministic Workflow implementations.
48
   *
49
   * @return true if the current execution happens as a part of workflow method and in a workflow
50
   *     thread context.
51
   */
52
  public static boolean isWorkflowThread() {
53
    return WorkflowInternal.isWorkflowThread();
×
54
  }
55

56
  /**
57
   * <b>Warning!</b> <br>
58
   * Never make workflow code depend on this flag as it is going to break determinism. The only
59
   * reasonable uses for this flag is deduping external never failing side effects like logging or
60
   * metric reporting.
61
   *
62
   * @return true if workflow code is being replayed. This method always returns false if called
63
   *     from a non workflow thread.
64
   */
65
  public static boolean isReplaying() {
66
    return WorkflowInternal.isReplaying();
1✔
67
  }
68

69
  /**
70
   * Runs the supplied procedure in the calling thread with disabled deadlock detection if called
71
   * from the workflow thread. Does nothing except the procedure execution if called from a
72
   * non-workflow thread.
73
   *
74
   * <p><b>Warning!</b> <br>
75
   * Never make workflow logic depend on this flag. Workflow code that runs into deadlock detector
76
   * is implemented incorrectly. The intended use of this execution mode is blocking calls and IO in
77
   * {@link io.temporal.payload.codec.PayloadCodec}, {@link
78
   * io.temporal.common.converter.PayloadConverter} or {@link
79
   * io.temporal.common.interceptors.WorkerInterceptor} implementations.
80
   *
81
   * @param proc to run with disabled deadlock detection
82
   */
83
  public static void deadlockDetectorOff(Functions.Proc proc) {
84
    deadlockDetectorOff(
×
85
        () -> {
86
          proc.apply();
×
87
          return null;
×
88
        });
89
  }
×
90

91
  /**
92
   * Runs the supplied function in the calling thread with disabled deadlock detection if called
93
   * from the workflow thread. Does nothing except the function execution if called from a
94
   * non-workflow thread.
95
   *
96
   * <p><b>Warning!</b> <br>
97
   * Never make workflow code depend on this flag. Workflow code that runs into deadlock detector is
98
   * implemented incorrectly (see {@link }). The intended use of this execution mode is blocking
99
   * calls and IO in {@link io.temporal.payload.codec.PayloadCodec}, {@link
100
   * io.temporal.common.converter.PayloadConverter} or {@link
101
   * io.temporal.common.interceptors.WorkerInterceptor} implementations.
102
   *
103
   * @param func to run with disabled deadlock detection
104
   * @return result of {@code func} execution
105
   * @param <T> type of {@code func} result
106
   */
107
  public static <T> T deadlockDetectorOff(Functions.Func<T> func) {
108
    return WorkflowInternal.deadlockDetectorOff(func);
1✔
109
  }
110

111
  /** Prohibit instantiation. */
112
  private WorkflowUnsafe() {}
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc