When working with ConcurrentLinkedQueue, how can I limit the size of the Queue. Is it possible that it will through outofmemory exception ?
The size of a ConcurrentLinkedQueue
is unbounded, so if producers are putting in items faster than consumers can remove them, eventually it will eat up your memory indeed. If you want to limit the size of the queue, try a blocking queue, such as LinkedBlockingQueue
or ArrayBlockingQueue
instead. The size of the first can be optionally bounded, while the second is always bounded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With