I would like to use a thread pool to process a list of items and then wait for them to complete. I also need to be able to time it out after 4 minutes of processing if they are not all completed.
This is what I have at the moment
ForkJoinPool threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors() * 2);
list.forEach(entry -> threadPool.execute(() -> {
// processing
}));
if (!threadPool.awaitQuiescence(4, TimeUnit.MINUTES)) {
// send alert about delay
}
The problem is that sometimes this approach will use the main thread to process one of the list items meaning that the awaitQuiescence will not start until after that one completes. Is there any other Thread Pool which allows something similar but guarantees not to use the main thread or is there a way to configure ForkJoinPool to not?