What I want to implement is a function that receives a list of business keys (=strings) and generate a process instance of a known process definition for each of the keys. I try to do that with the following code:
private void startInstances(List<String> keys) {
for (Object key : keys) {
runtimeService.createProcessInstanceByKey("process1")
.businessKey(key)
.execute();
}
}
This code works, but it isn’t very performant when I deal with larger lists in the range of 10.000 entries and above. It seems to take about 1 second for every 10 entries or 15 minutes for 10.000 entries. To improve performance I tried to execute it in parallel with the following variant:
private void startInstances(List<String> keys) {
keys.parallelStream().forEach((key) -> {
runtimeService.createProcessInstanceByKey("process1")
.businessKey(key)
.execute();
});
}
This improved performance a lot, but I’m not 100% sure if this is a solid implementation (due to possible threading problems).
Also I have read about supported batch operations (see here ) but just the operation to create new process instances seems to be missing. Do you have any tips or alternative approaches?
Thanks in advance