Hi,I have problem when use asynchronous service tasks with "no exclusice" option.Some task are executed more than once (somtimes twice or triple).Process defintion:Start Event -> Parallel Gateway -> four parell service Tasks (No1..4) -> Parallel Gateway -> End EventResult of sinle execute process in attached log file.Every exeucte serice task is logged: serviceNo1..4.executedAnd "initial.result"/"final.result" is reading the process state.initial - on start processfinall - after 10 sec (if process is still alive)
public ProcessResult readProcessResult(String processId) {
HistoricProcessInstance hs = historyService.createHistoricProcessInstanceQuery().processInstanceId(processId)
.includeProcessVariables().singleResult();
Map<String, Object> variables = hs.getProcessVariables();
ProcessResult result = new ProcessResult();
result.setProcessId(hs.getId());
result.setDurationInMillis(hs.getDurationInMillis());
result.setResultExec1((String) variables.get("ExecuteS1"));
result.setResultExec2((String) variables.get("ExecuteS2"));
result.setResultExec3((String) variables.get("ExecuteS3"));
result.setResultExec4((String) variables.get("ExecuteS4"));
return result;
}
Services code:
@Service("serviceNo1")
public class ServiceNo1Impl implements ServiceNo1 {
private static final Logger LOG = LoggerFactory.getLogger(ServiceNo1Impl.class);
@Override
public void execute(DelegateExecution execution) throws Exception {
// do something…
execution.setVariable("ExecuteS1", "OK");
LOG.debug("serviceNo1.executed");
}
}
Spring Boot Request code:
@RequestMapping(value = "/postAppExcl", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ProcessResult processUserApplicationExcl(@RequestBody JobApplication jobApplication)
throws InterruptedException {
Map<String, Object> vars = Collections.<String, Object> singletonMap("jobApplication", jobApplication);
String executionId = null;
// start Activiti process
identityService.setAuthenticatedUserId(activitiUsername);
ProcessInstance process = runtimeService.startProcessInstanceByKey("myProcessJobAppExcl", vars);
executionId = process.getProcessInstanceId();
LOG.debug("myProcessJobApp: executionId=" + executionId);
// read process result
ProcessResult result = serviceResult.readProcessResult(executionId);
LOG.debug("initial.result=" + result);
// try 10 times (with 1sec wait between read state)(
if (result.getDurationInMillis() == null) {
for (int i = 1; i <= 10; i++) {
Thread.sleep(1000);
result = serviceResult.readProcessResult(executionId);
// LOG.debug(i + ". result=" + result);
if (result.getDurationInMillis() != null) {
LOG.debug("End process with executionId=" + executionId);
break;
}
}
if (result.getDurationInMillis() == null) {
LOG.debug("Process executionId=" + executionId + " not completed… yet ");
}
}
LOG.debug("final.result=" + result);
return result;
}
I can attach example source projects, where all ServiceTaska executions are writen to output log.