I created a Java LinkedBlockingQueue like new LinkedBlockingQueue(1) to limit the size of the queue to 1. However, in my testing, this seems to be ignored and there is often several things in the queue at any given time. Why is this?
A:
How did check the number of entries in the queue? If you call size(), it should always return 0 or 1.
When the queue reaches the capacity, the put() call simply block. When you have very short tasks, this may give you the illusion that multiple things are in the queue.
ZZ Coder
2010-05-03 22:04:02
the problem seemed to be that things were printing to the console not in the correct order, so it looked like multiple things were in there. But you are right, size() always displays 1 or 0.
tgguy
2010-05-03 22:06:03