Temporal SDK allows you to use Continue-As-New in various ways.
To continue execution of the same Workflow that is currently running, use:
To continue execution of a currently running Workflow as a completely different Workflow type, use
For example, in a Workflow class called
MyWorkflow, we can create a Workflow stub with a different type, and call its Workflow method to continue execution as that type:
MyOtherWorkflow continueAsNew = Workflow.newContinueAsNewStub(MyOtherWorkflow.class);
ContinueAsNewOptions options in
ContinueAsNewOptions options = ContinueAsNewOptions.newBuilder()
MyOtherWorkflow continueAsNew = Workflow.newContinueAsNewStub(MyOtherWorkflow.class, options);
Providing these options allows you to continue Workflow Execution as a new Workflow run, with a different Workflow Type, and on a different Task Queue.
Java Workflow reference: https://www.javadoc.io/doc/io.temporal/temporal-sdk/latest/io/temporal/workflow/package-summary.html