0

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!

2
  • Have you looked at all the implementations of the Queue interface in its javadoc? Pick your poison. Commented Jul 21, 2013 at 21:20
  • Actually I am able to implement queue. What I need is multiple queues and a single thread.. Commented Jul 21, 2013 at 21:27

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
@user2110873 - there is no such API. You need to implement this yourself as described in this Answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.