How to efficiently implement balanced request queueing in Java?
I need to implement a balanced and highly efficient queue system to process a large number of requests. I have a Worker class that holds an internal queue for executing requests, and each Worker has a unique ID from 1 to n (where n is the total number of workers). If the number of requests exceeds a certain threshold (e.g., 1000), I want to distribute these requests evenly among multiple Worker instances (for example, with 10,000 requests and 1000 workers, each worker would handle about 10 requests). What is the best way to achieve this in Java? Are there any built-in classes or libraries that can help implement this solution both efficiently and clearly? Thank you for your advice!
4 Replies
⌛ This post has been reserved for your question.
Hey @John Regan! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Are the workers in the same process? If so, why not just use
ExecutorService?alternatively take a look at
LinkedBlockingQueue or the other BlockingQueue instances: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/concurrent/BlockingQueue.htmlBlockingQueue (Java SE 21 & JDK 21)
declaration: module: java.base, package: java.util.concurrent, interface: BlockingQueue
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.