Say I have a queue full of tasks which I need to submit to an executor service. I want to process them in parallel. That's cover.
private ExecutorService service = Executors.newFixedThreadPool(5);
I recive 20 tasks to be executed, and all of there are processed as I expected in groups of 5.
service.execute(tasks.poll());
But now I want to keep adding tasks to the queue and process them as I do now, but the service finish after the 20 original tasks.
How can I do this?
executor.awaitTermination()
这将等待所有任务完成,这应该在executorl.shutdown()之后使用
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.