Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Using Java I need to implement the following architecture: There are multiple queues with jobs continuously coming in the queues. There is a single thread picking up jobs from the queues following a scheduling algorithm. I should be able to write my own scheduling algorithm. Can you please tell me which Java API to use to implement this? I have used ThreadPoolExecutor, but with this I could implement a single job queue and a thread pool containing multiple threads. Thanks in advance!

share|improve this question
Have you looked at all the implementations of the Queue interface in its javadoc? Pick your poison. – JB Nizet Jul 21 at 21:20
Actually I am able to implement queue. What I need is multiple queues and a single thread.. – kajarigd Jul 21 at 21:27
add comment (requires an account with 50 reputation)

1 Answer

Use multiple concurrent queues and one semaphore. In the producers, push objects and signal the semaphore. In the one consumer, wait on the 'common' semaphore and then poll the queues according to your scheduling algorithm - one of them must have an object on it.

share|improve this answer
Thanks for your reply! Can you please tell me how to use multiple queues. I am not aware of any Java API, which will allow me to have multiple queues. – kajarigd Jul 21 at 21:25
1  
@user2110873 - there is no such API. You need to implement this yourself as described in this Answer. – Stephen C Jul 21 at 22:33
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.