cancel
Showing results for 
Search instead for 
Did you mean: 

How do Timer intermediate catching event work?

strae
Champ in-the-making
Champ in-the-making
There are process:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="Timer1" name="Timer1">
    <startEvent id="startevent1" name="Start">       
    </startEvent>  
    <endEvent id="endevent1" name="End"></endEvent>
    <serviceTask id="servicetask1" name="Service Task" activiti:class="org.activity.timer.Service2"></serviceTask>     
      <intermediateCatchEvent id="timer1" name="Timer1">
          <timerEventDefinition id="tmrcfg1">
              <timeDuration>PT100S</timeDuration>
         </timerEventDefinition>
      </intermediateCatchEvent> 
      <sequenceFlow id="flow1003" name="" sourceRef="timer1" targetRef="servicetask1"></sequenceFlow>
      <sequenceFlow id="flow1001" name="" sourceRef="startevent1" targetRef="timer1"></sequenceFlow>
      <sequenceFlow id="flow1002" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
  </process>
</definitions>

I run it by java code:
public static void main(String[] args) {
Deployment deployment = ProcessEngines.getDefaultProcessEngine().getRepositoryservice()
            .createDeployment().addClasspathResource("Timer1").deploy();
ProcessEngines.getDefaultProcessEngine().getRuntimeservice().startProcessInstanceByKey("Timer1").getId();
}

I except that java thread start process and runtime is: from start event go to intermediateCatchEvent,  on the intermediateCatchEvent process wait 100 sec(as in configuration), then process go to serviceTask, from service task to end. But thread run without timeout 100 sec and serviceTask run immediately. What is the problem?
ServiceTask implementation:
public class Service2 implements JavaDelegate {
   public void execute(DelegateExecution execution) throws Exception {
      System.out.println("Process 2  done");
   }
}
7 REPLIES 7

jbarrez
Star Contributor
Star Contributor
When execution arrives at the timer event, it doesnt use your thread for waiting. If we would do that, it woudldnt be good for performance.
So a background threadpool is taking care of executing the rest of the process.

So that explains what you see: the main method executed, but the background thread pool has never the time to kick in.

strae
Champ in-the-making
Champ in-the-making
When execution arrives at the timer event, it doesnt use your thread for waiting. If we would do that, it woudldnt be good for performance.
So a background threadpool is taking care of executing the rest of the process.

So that explains what you see: the main method executed, but the background thread pool has never the time to kick in.
Thanks for the reply,  but

Whot do you mean about "background thread pool"? I want to run simple bpmn process that first wait the timeout then execute servicetask. Process must have only one instance and run in single thread. Timer have to be configurated by  bpmn. I do not want implement timer in my java code,  for exemple in service task.

jbarrez
Star Contributor
Star Contributor
To be able to run timers, enable the job executor as described in http://activiti.org/userguide/index.html#jobExecutorConfiguration. That takes care of the backrgound thread pool.

My point is: if you run in a simple main() method, your process will always stop before it reaches the end state, because your main() methods stops and kills all associated threads.

sonam_ag
Champ in-the-making
Champ in-the-making
Am starting to explore Activiti and using timer before my next service task.
Had to set activiti:async="true" and set the property <code><property name="jobExecutorActivate" value="true" /> </code> to make my one minute timer to work.

Am using a test class to deploy and run instances. After the first instance is created my program exits. Again after a minute I rerun my code(no new instance needed just deploy), the pending service process from the previous instance gets completed.

Wanted to know how is it working? How is the state managed in Activiti?
Do I need to deploy each time or can I keep my program running until all associated threads are over.
Can the system crash?

jbarrez
Star Contributor
Star Contributor
"How is the state managed in Activiti?"

The state of the process instance is stored as a tree of 'executions', stored in ACT_RU_EXECUTION table.

The timers are 'jobs' and are stored in the 'ACT_RU_JOB' table.

The system can crash, but we're relying on database transaction to bring us from one stable state to the other. If the system crashed, the transaction will be rolled back and the process instance will be in the previous stable state.

hardiku
Champ in-the-making
Champ in-the-making
I am facing very strange behavior of intermediate and boundary event timers. They are working fine in development environment, where i have inspected startTime,dueDate and endTime, every thing is fine (only one activiti engine against one db).

But in QA environment it behaves weird. It does not wait for specified time duration though dueDate is seems to be correct. It executes almost immediately irrespective of time duration specified. I found very strange endTime for the same. Below is the example of such strange timer execution:

start_time_(act_hi_actinst)=2015-12-22 12:54:53.267
duedate_(act_ru_job)=2015-12-22 12:59:58.67  (5 minutes delay)
end_time_(act_hi_actinst)=2015-12-22 18:24:56.997
duration_(act_hi_actinst)=19803728 (strange, its GMT offset, should be 300000)

I have two activiti engines against one db in QA for LB. I don't understand what's going wrong here ?

vasile_dirla
Star Contributor
Star Contributor
Hi,
@hardiku, since you have two engines did you check if the clock of these machines (where engines are deployed) are in sync ? (this is the first thing which comes in my mind now)