简体   繁体   中英

In java, how to process items off a bounded queue with at most N threads, with adjustable N?

Let's say in Java I have a bounded BlockingQueue and I want to process items off that queue with at most N threads. The amount N should be adjustable. The solution should take not more than N items off the queue, such that it preserves its role as providing back pressure. How would I achieve this?

I got a long way with http://jcip.net/listings/BoundedExecutor.java , but that doesn't really allow for resizes.

也许您可以升级类http://jcip.net/listings/BoundedExecutor.java以提供可以向Semaphore添加更多许可的功能(您可以使用release(int许可)添加更多许可)并使用CachedThreadPool来提供您需要的灵活性?

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