Cancel currently running workflow from its running activity

Hello temporal folks,

  • How can I forcefully terminate workflow (without cleaning up resources) v/s graceful termination of workflow (cleaning up resources) programmatically using java sdk. Can you share an example of each case ?

You can look at the following samples:

  1. Terminate via api: samples-java/src/main/java/io/temporal/samples/terminateworkflow at master · temporalio/samples-j and associated test:
    samples-java/src/test/java/io/temporal/samples/terminateworkflow at master · temporalio/samples-j
  2. Cancellation: samples-java/HelloCancellationScope.java at master · temporalio/samples-java · GitHub and samples-java/HelloDetachedCancellationScope.java at master · temporalio/samples-java · GitHub

I would also consider reading this thread to learn more about cancellation.

Note that you can canel/terminate workflows also via tctl - Temporal CLI - tctl | Temporal documentation