ExecutorService executor = ****;
List<List<Object>> objectGroup = Lists.partition(objectList, 5);
for (List<Object> eachGroup : objectGroup ) {
CountDownLatch latch = new CountDownLatch(eachGroup.size());
for (Object obj: eachGroup) {
executor.submit(() -> {
doTask(obj);
latch.countDown();
});
}
try {
if (!latch.await(15, TimeUnit.MINUTES)) {
// todo close all thread in executor
}
}
catch (InterruptedException e) {
System.out.println();
}
}
**
I want to close all thread in executor
after 15 minutes but I do not know how to close.
Someone said to use executor.shutDownNow()
but it will close the executor (I can not submit thread anymore), I don't want that to happen
**