cancel
Showing results for 
Search instead for 
Did you mean: 

Suspending process instance

garuh
Champ in-the-making
Champ in-the-making
<b>My scenario:</b>

Start -> Service task 1 -> Service task 2 -> End

Service tasks have Java delegates which runs some long time logic (ie. file processing). Because we don't want task to block transaction and we don't want to use Receive tasks, for some reasons, so I thought that I can use process instance suspend method in my java delegate:

runtimeService.suspendProcessInstanceById(execution.getProcessInstanceId()); 


Than I pass information about this process execution to some external thread:

new ProcessThread(execution.getProcessInstanceId(), execution.getId()).start();


This external thread will activate process after its job will be done, using this:

runtimeService.activateProcessInstanceById(processInstanceId);


<b>Problem:</b>

The thing is that process isn't at suspended at all. Mine service tasks are asynchronous and exclusive (I know, that's stupid), but I was expecting that when I tell Activity to suspend process instance in java delegate execution than Activity will stop processing next tasks and wait, like it is when it reaches user or receive task.

<b>Question:</b>

Is it event possible? How can I stop process execution when I wan to? Maybe I can stop job executor somehow, but is it available in java delegate?


Thank you in advance for any help.
2 REPLIES 2

garuh
Champ in-the-making
Champ in-the-making
I was searching more through your forum and founded many disturbing topics saying that this scenario is not possible Smiley Sad This is really strange cause this suspending method should work like this, that is intuitive. I founded also that there was bu in JIRA about that:

http://jira.codehaus.org/browse/ACT-1401

and it was fixed in 5.11 version. There was also new feature JIRA ticket for it:

http://jira.codehaus.org/browse/ACT-1457

So is this should work or not? I will try to modify your code to make it work, but if you will have some clues about that please write them.

garuh
Champ in-the-making
Champ in-the-making
We found out the solution. First of all in our scenario we have to implement ActivityBehavior interface, not JavaDelegate, precisely SignallableActivityBehavior interface. When execution of task implemented with this interface ends, process flow stops, so after our thread finishes its job, it can signal execution of this task and take appropriate transition ie. 

1. Service task execution method:

<code>
public void execute(ActivityExecution execution) throws CodeException, InterruptedException {

    new ProcessThread(execution).start();
}
</code>

2. External example thread run method:

<code>
public void run() {

  try {
   sleep(10000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  runtimeService.signal(execution.getId());
}
</code>

3. Service task implementation of SignallableActivityBehavior needs override signal method:

<code>
@Override
public void signal(ActivityExecution execution, String signalEvent,
   Object signalData) throws Exception {
 
PvmTransition transition = execution.getActivity().getOutgoingTransitions().get(0);
        execution.take(transition);
}
</code>

This is more less simple way of making process suspend and then activate it from place it ended.