简体   繁体   中英

ExecutorService add tasks dynamically

I have ExecutorService for 10 tasks, and I want to handle eg 24 tasks. First 10 tasks I can add immediately, but when some task complete I want to add another one.

Is there some best practice, common approach or pattern to implement this behavior?

Executors have s queue¹ for keeping tasks while waiting for threads to become available to process them. You don't need to do anything special, just submit tasks to the executor as you please.

¹ This is not strictly true, and the queue may be limited. However in the general use case (unless otherwise indicated), the queue is unlimited and you don't need to worry about it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM