Temporal Workflow resumability

( We are using Java SDK and this question is in that context )
I read that if the worker dies and is started again, the workflow will resume.

  1. How is this possible considering that WF is Java? What if it was in the middle of a for() loop ? Will it resume from the exact position loop was in when the worker crashed?
  2. Will the workflow private variables be restored when Workflow is resumed? What about Java volatile variables?
  3. Will the search attributes be restored on the Workflows?

–sony

  1. Yes, it is going to be resumed from the exact position. It is done by replaying the workflow code from the beginning. The assumption is that the workflow is deterministic which imposes some constraints on the way the code is written.
  2. Yes, all variables will be restored. The same applies to volatile variables. But you don’t need them as any synchronization and locking primitives are prohibited within the workflow code.
  3. Yes.

Thank you for the response Maxim.
( Sorry ) it is still not clear what exactly is meant by resumability - I did read the link you sent )

Please consider the following

//@WorkflowInterface implementation
public class ProcessingWorkflow implements MyWorkflowInterface {


	int instanceVar =0;
    //@WorkflowMethod
    String myWorkflow(Arguments args) {
	instanceVar = foo() ;
	int stackvar = bar() ;

        for(int i = 0 ; i< 88 ; i++ )
		//JVM/Worker crashes when i = 12
		stackvar = i ;
	}

    }
}
  1. In the above code, JVM/Worker crashes when the Java loop is midway ( i=12 ). When the Worker is restarted, will teh workflow resume starting from the middle of teh method with i = 13 ?

  2. If it does not resume with i=13, will myWorkflow() method start executing from the beginning again ?

  3. If it will restart from the beginning, what will be teh value of instanceVar ? ( will it be 0 ? or will it be the value it was when JVM crashed ? )

–sony

  1. You want to add some blocking code (like workflow sleep or an activity invocation) in the loop. There is no any externally observable behavior while the loop is running so interrupting it or recovering in the middle is not really visible. For example the following code:
        for(int i = 0 ; i< 88 ; i++ )
              Workflow.sleep(1000);
		//JVM/Worker crashes when i = 12
		stackvar = i ;
	}

will resume in the middle of the loop with i = 13.

( Thank you so very much Maxim for your diligent responses )
How is that possible - from a Java point of view, even if you use reflection to restore object variables - to start executing a method from the middle on a freshly created JVM ?
( unless you use some kind of byte code rewriting )

Earlier you mentioned " It is done by replaying the workflow code from the beginning"

Will you please explain how it is possible from a Java point of view.

This conference talk explains the recovery procedure starting from minute 35.