简体   繁体   中英

how to bound the number of threads running simultaneously

Let's say i've got a list which holds 100 threads inside it.

i want to allow only 5 threads run simultaneously until all my threads in list have done their job.

i also can't use the java threadpool for this task.

could you give me a clue how to bound the number of my running threads?

I think what you need is semaphore . Check the doc. Briefly speaking, semaphore is a locking method. You ask the resource from the semaphore singleton class, which is process scope unique, control the running number of function process.

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