@@ -162,7 +162,7 @@ APIs that generate random numbers, random UUIDs, or the current date are _non-de
162162
163163For example, instead of this:
164164
165- {{< tabs ".NET" >}}
165+ {{< tabs ".NET" Java >}}
166166
167167{{% codetab %}}
168168
@@ -175,11 +175,22 @@ string randomString = GetRandomString();
175175
176176{{% /codetab %}}
177177
178+ {{% codetab %}}
179+
180+ ``` java
181+ // DON'T DO THIS!
182+ Instant currentTime = Instant . now();
183+ UUID newIdentifier = UUID . randomUUID();
184+ string randomString = GetRandomString();
185+ ```
186+
187+ {{% /codetab %}}
188+
178189{{< /tabs >}}
179190
180191Do this:
181192
182- {{< tabs ".NET" >}}
193+ {{< tabs ".NET" Java >}}
183194
184195{{% codetab %}}
185196
@@ -192,6 +203,17 @@ string randomString = await context.CallActivityAsync<string>("GetRandomString")
192203
193204{{% /codetab %}}
194205
206+ {{% codetab %}}
207+
208+ ``` java
209+ // Do this!!
210+ Instant currentTime = context. getCurrentInstant();
211+ Guid newIdentifier = context. NewGuid ();
212+ String randomString = context. callActivity(GetRandomString . class. getName(), String . class). await();
213+ ```
214+
215+ {{% /codetab %}}
216+
195217{{< /tabs >}}
196218
197219
@@ -202,20 +224,58 @@ Instead, workflows should interact with external state _indirectly_ using workfl
202224
203225For example, instead of this:
204226
227+ {{< tabs ".NET" Java >}}
228+
229+ {{% codetab %}}
230+
205231``` csharp
206232// DON'T DO THIS!
207233string configuration = Environment .GetEnvironmentVariable (" MY_CONFIGURATION" )! ;
208234string data = await new HttpClient ().GetStringAsync (" https://example.com/api/data" );
209235```
236+ {{% /codetab %}}
237+
238+ {{% codetab %}}
239+
240+ ``` java
241+ // DON'T DO THIS!
242+ String configuration = System . getenv(" MY_CONFIGURATION" );
243+
244+ HttpRequest request = HttpRequest . newBuilder(). uri(new URI (" https://postman-echo.com/post" )). GET (). build();
245+ HttpResponse<String > response = HttpClient . newBuilder(). build(). send(request, HttpResponse . BodyHandlers . ofString());
246+ ```
247+
248+ {{% /codetab %}}
249+
250+ {{< /tabs >}}
210251
211252Do this:
212253
254+ {{< tabs ".NET" Java >}}
255+
256+ {{% codetab %}}
257+
213258``` csharp
214259// Do this!!
215260string configuation = workflowInput .Configuration ; // imaginary workflow input argument
216261string data = await context .CallActivityAsync <string >(" MakeHttpCall" , " https://example.com/api/data" );
217262```
218263
264+ {{% /codetab %}}
265+
266+ {{% codetab %}}
267+
268+ ``` java
269+ // Do this!!
270+ String configuation = ctx. getInput(InputType . class). getConfiguration(); // imaginary workflow input argument
271+ String data = ctx. callActivity(MakeHttpCall . class, " https://example.com/api/data" , String . class). await();
272+ ```
273+
274+ {{% /codetab %}}
275+
276+ {{< /tabs >}}
277+
278+
219279#### Workflow functions must execute only on the workflow dispatch thread.
220280The implementation of each language SDK requires that all workflow function operations operate on the same thread (goroutine, etc.) that the function was scheduled on. Workflow functions must never:
221281- Schedule background threads, or
@@ -225,20 +285,58 @@ Failure to follow this rule could result in undefined behavior. Any background p
225285
226286For example, instead of this:
227287
288+ {{< tabs ".NET" Java >}}
289+
290+ {{% codetab %}}
291+
228292``` csharp
229293// DON'T DO THIS!
230294Task t = Task .Run (() => context .CallActivityAsync (" DoSomething" ));
231295await context .CreateTimer (5000 ).ConfigureAwait (false );
232296```
297+ {{% /codetab %}}
298+
299+ {{% codetab %}}
300+
301+ ``` java
302+ // DON'T DO THIS!
303+ new Thread (() - > {
304+ ctx. callActivity(DoSomethingActivity . class. getName()). await();
305+ }). start();
306+ ctx. createTimer(Duration . ofSeconds(5 )). await();
307+ ```
308+
309+ {{% /codetab %}}
310+
311+ {{< /tabs >}}
233312
234313Do this:
235314
315+ {{< tabs ".NET" Java >}}
316+
317+ {{% codetab %}}
318+
236319``` csharp
237320// Do this!!
238321Task t = context .CallActivityAsync (" DoSomething" );
239322await context .CreateTimer (5000 ).ConfigureAwait (true );
240323```
241324
325+ {{% /codetab %}}
326+
327+ {{% codetab %}}
328+
329+ ``` java
330+ // Do this!!
331+ ctx. callActivity(DoSomethingActivity . class. getName()). await();
332+ ctx. createTimer(Duration . ofSeconds(5 )). await();
333+ ```
334+
335+ {{% /codetab %}}
336+
337+ {{< /tabs >}}
338+
339+
242340### Updating workflow code
243341
244342Make sure updates you make to the workflow code maintain its determinism. A couple examples of code updates that can break workflow determinism:
0 commit comments