How to cancel a worklow which is sleeping?

Let’s say I have a worklow which is sleeping using Workflow.sleep(). How the workflow can be cancelled or I have to do one of the below

  1. Use terminate instead of cancel or
  2. Workflow.await() along with @SignalMethod should be used to finish the workflow

I am using Java SDK.

There are many ways. The simplest one IMHO:

Workflow.newTimer().cancellableGet()

If you want to handle cancellation explicitly, you can always get a Promise that becomes ready when a scope is canceled.

Promise<String> cancellationPromise = CancellationScope.current().getCancellationRequest();

If you want to handle the notification asynchronously, use Promise.thenAppy or Promise.handle.