Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-sizeable Java BlockingQueue

So I am using a fixed sized BlockingQueue [ArrayBlockingQueue] in a producer/consumer type application, but I want the user to be able to change the queue size on the fly. Problem is there is not a BlockingQueue implementation that allows changing capacity after creation. Anyone ever come across this before? Any ideas?

like image 933
Gandalf Avatar asked Jul 06 '11 16:07

Gandalf


2 Answers

The most obvious solution (may or may not be appropriate depending on your circumstances) would be to simply instantiate a new queue with the updated capacity you want. Then push everything from the old queue into the new queue.

like image 110
Dan Tao Avatar answered Sep 21 '22 23:09

Dan Tao


You could extend LinkedBlockingQueue. Its limit is is a soft limit (i.e. just an additional check) and you could make this something you can change (by disabling the built in one and putting in your own)

like image 29
Peter Lawrey Avatar answered Sep 19 '22 23:09

Peter Lawrey