Delayed execution of workflow

Hi there! I’m working on a temporal workflow with the Java SDK, and I’d like to optionally delay starting execution of the workflow – potentially for a long period of time (on the order of days or weeks). The first thing I found and tried was Workflow.sleep at the beginning of the workflow implementation, but I wasn’t sure if I should sleep for long periods using that.

Is that the preferred way to delay execution of a workflow, or is there a better method?

Yes, Workflow.sleep is the way to go. There is no limit on how long the workflow is allowed to sleep giving that DB has enough space to keep all the sleeping workflows.

In the latest version of the Temporal SDK and with the latest Temporal server, you can use WorkflowOptions to specify the start delay.

1 Like