ProcessInstance.isEnded() not becoming true when UserTask is in flow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 10:52 AM
I am testing integration of the Activiti engine in a fairly direct fashion (no Tomcat or other container, no spring). So far, so good! I am able to build a custom ServiceTask that calls my JavaDelegate execute() method, access and set variables, and so on. I am also able to call complete() on a UserTask inserted into the process, and I can see that it executes and moves to the next task.
However, while the process without a UserTask completes, the process with a UserTask does not. I can see this calling ProcessInstance.isEnded() and also in the debug log. There must be something trivial I am missing, but I cannot figure it out.
I've packaged this into a simple standalone maven project with a main() and attached the whole project. The main() is shown below.
The attached "activiti-tester.txt" can be renamed to activiti-tester.zip (I hope) for extraction. I've been building with Netbeans, but Eclipse should also work.
When doTest2=true, it runs "test2.bpmn", which is only the service task, and all is well. When doTest2=false, it runs "test1.bpmn" including the user task, and it does not seem to end.
Any help is much appreciated!
public static void main(String[] args) throws Exception {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
DeploymentBuilder db = repositoryService.createDeployment();
Deployment d = db.addClasspathResource("test1.bpmn").addClasspathResource("test2.bpmn").deploy();
RuntimeService runtimeService = processEngine.getRuntimeService();
Map<String, Object> variableMap = new HashMap<>();
variableMap.put("name", "john");
System.out.println("Starting");
boolean doTest2 = false;
ProcessInstance processInstance = null;
if (doTest2) {
processInstance = runtimeService.startProcessInstanceByKey("test2", variableMap);
} else {
processInstance = runtimeService.startProcessInstanceByKey("test1", variableMap);
System.out.println("Returned");
String activityId = processInstance.getActivityId();
List<Task> tasks = taskService.createTaskQuery().processInstanceBusinessKey(processInstance.getBusinessKey()).list();
Map<String,Object> vars = new HashMap<>();
vars.put("address", "pobox 16");
taskService.complete(tasks.get(0).getId(), vars);
}
System.out.println("process ended? " + processInstance.isEnded());
Thread.sleep(2000);
System.out.println("process ended? " + processInstance.isEnded());
}
However, while the process without a UserTask completes, the process with a UserTask does not. I can see this calling ProcessInstance.isEnded() and also in the debug log. There must be something trivial I am missing, but I cannot figure it out.
I've packaged this into a simple standalone maven project with a main() and attached the whole project. The main() is shown below.
The attached "activiti-tester.txt" can be renamed to activiti-tester.zip (I hope) for extraction. I've been building with Netbeans, but Eclipse should also work.
When doTest2=true, it runs "test2.bpmn", which is only the service task, and all is well. When doTest2=false, it runs "test1.bpmn" including the user task, and it does not seem to end.
Any help is much appreciated!
public static void main(String[] args) throws Exception {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
DeploymentBuilder db = repositoryService.createDeployment();
Deployment d = db.addClasspathResource("test1.bpmn").addClasspathResource("test2.bpmn").deploy();
RuntimeService runtimeService = processEngine.getRuntimeService();
Map<String, Object> variableMap = new HashMap<>();
variableMap.put("name", "john");
System.out.println("Starting");
boolean doTest2 = false;
ProcessInstance processInstance = null;
if (doTest2) {
processInstance = runtimeService.startProcessInstanceByKey("test2", variableMap);
} else {
processInstance = runtimeService.startProcessInstanceByKey("test1", variableMap);
System.out.println("Returned");
String activityId = processInstance.getActivityId();
List<Task> tasks = taskService.createTaskQuery().processInstanceBusinessKey(processInstance.getBusinessKey()).list();
Map<String,Object> vars = new HashMap<>();
vars.put("address", "pobox 16");
taskService.complete(tasks.get(0).getId(), vars);
}
System.out.println("process ended? " + processInstance.isEnded());
Thread.sleep(2000);
System.out.println("process ended? " + processInstance.isEnded());
}
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 12:01 PM
Hmmm, when I add this trace line:
System.out.println("process count=" + runtimeService.createProcessInstanceQuery().count());
It prints 0, so I assume that the process instance actually ended, but for some reason the isEnded() status didn't get set in the in-memory ProcessInstance for some reason? I guess that's not a problem, just not what I was expecting.
System.out.println("process count=" + runtimeService.createProcessInstanceQuery().count());
It prints 0, so I assume that the process instance actually ended, but for some reason the isEnded() status didn't get set in the in-memory ProcessInstance for some reason? I guess that's not a problem, just not what I was expecting.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2016 05:11 AM
Hi John,
Did you update process instance?
Regards
Martin
Did you update process instance?
Regards
Martin
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2016 09:20 AM
I don't know what that means. ProcessInstance doesn't seem to have an update() or refresh() method…
I tried this:
ProcessInstance processInstance2 = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(processInstance.getBusinessKey()).list().get(0);
But I get an NPE. I tried this:
ProcessInstance processInstance2 = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).list().get(0);
but I get an empty list.
It seems that once the process instance is finished, its record goes away too, and there is nothing to refresh. Which kind of makes sense…
Thanks,
john
I tried this:
ProcessInstance processInstance2 = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(processInstance.getBusinessKey()).list().get(0);
But I get an NPE. I tried this:
ProcessInstance processInstance2 = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).list().get(0);
but I get an empty list.
It seems that once the process instance is finished, its record goes away too, and there is nothing to refresh. Which kind of makes sense…
Thanks,
john
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2016 11:53 AM
Indeed, if process ends, it's not in runtimeService anymore, you can find it in historyService if you want, but that's another story.