AnsweredAssumed Answered

Timer in standalone application

Question asked by santoshpatel on Feb 26, 2016
Latest reply on Mar 1, 2016 by martin.grofcik

We are trying to create a standalone application in Java using Activiti APIs. We have been trying to add timer to execute a certain flow after the given time-out. But this is not working as per the expectation. Below is the sample code.

  public static void main (String[] args) {
       ProcessEngine processEngine=ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().buildProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        RuntimeService runtimeService = processEngine.getRuntimeService();
       ProcessInstance pi = runtimeService.startProcessInstanceByKey("escalationExample");
       // There should be one task, with a timer : first line support
       TaskService taskService = processEngine.getTaskService();
       Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
       System.out.println("First line support = " + task.getName());
       // Manually execute the job
       ManagementService managementService = processEngine.getManagementService();
       Job timer = managementService.createJobQuery().singleResult();

       // The timer has fired, and the second task (secondlinesupport) now exists
       task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
       System.out.println("Handle escalated issue = " + task.getName());

We are expecting "escalated issue task" i.e. "secondlinessupport" should be executed after the time-out of 5 min. What is wrong with the code?
Is there any way to handle the timer event and how?