Reputation: 35
I have 2 queues A and B. Main thread is responsible for filling the queues. There is a threadpool of 3 threads responsible for reading from queues. Both Queues are ArrayBlockingQueue. Lets say main thread is filling the queues in this way (A1,B1),(A2,B2),(A3,B3),(A4,B4) and so on. A1 and B1 collectively makes a whole data. Is it possible for a any thread to read data like (A3,B4) at any point. If yes then how can i avoid it. I want every thread to read data the altogether. e.g thread1 should read both (A1,B1) and thread2 (A2,B2) and so on.
Upvotes: 1
Views: 84
Reputation: 140457
As so often, the answer is: depends.
Of course you can implement something that would follow the outlined approach and that in the end is "correct". But: getting there will be hard.
A much more straight forward way: fix your broken design. If the two entries within the two queues are only meaningful together - then create a class that wraps around one A and one B - and put such objects into a single queue.
Upvotes: 3