Prevent ConcurrentLinkedQueue <T> from outofmemory Exception
When working with ConcurrentLinkedQueue, how can I limit the size of the queue. Is this possible due to exceeding the exception?
+6
Youval
source share2 answers
The size of the ConcurrentLinkedQueue unlimited, so if manufacturers place items faster than consumers can remove them, in the end they will really eat. If you want to limit the size of the queue, try locking the queue, such as LinkedBlockingQueue or ArrayBlockingQueue . The size of the first may not necessarily be limited, and the second is always limited.
+5
Péter Török
source shareI was a bit late for this one, but you can always set the upper limit and when it is exceeded, your method will consume one token to make room for the next, etc.
0
MarioBGonzalez
source share