One way of doing this in Mendix is as follows:
Use the following code in the Java action.
// BEGIN USER CODE
//This execute a microflow for each input object
//The input microflow is expected to update its input object with the results of the API call
HashMap<String, Object> parameters = new HashMap<String, Object>();
ArrayList<Future<Object>> futures = new ArrayList<Future<Object>>();
for (Product product : productList) {
parameters.put("Product", product);
Future<Object> future = Core.executeAsync(this.getContext(), microflow, false, parameters);
futures.add(future);
}
//future.get() is a blocking call. Only resume when all executions have been completed.
for (Future<Object> future : futures) {
future.get();
}
return true;
// END USER CODE
The idea is to execute a microflow for each input object. This microflow should result in an updated object (so you only return a boolean, not some list of objects, as that increases complexity of the Java code). You call these microflows asynchronously through Java (Core.executeAsync()). These microflows result in futures. You iterate over the futures, and future.get() waits until the microflow has finished. This means you only continue once all microflows have finished.
Note: I have not actually tested this code, I recreated it from other projects where I have used it.
More a stackoverflow question: https://stackoverflow.com/questions/51461491/calling-multiples-webservices-at-same-time-using-java
Regards,
Ronald
Hi Wouter,
I have used this App store Module for one of the project to make Parallel execute
https://marketplace.mendix.com/link/component/116433
It worked as expected running 500 REST API calls multithreaded at a time.