Which Java blocking queue is best for multiple producer and single or multiple consumers scenarios?
I am testing with LinkedBlockingQueue but I am getting OutOfMemoryError exception.
I am trying to achieve following things.
The problem is not which
Queue implementation you use but rather how to approach the problem of throttling your producers if your consumers cannot keep up. One possible solution is to create a
LinkedBlockingQueue with a fixed capacity, and have your producers call
offer(E e), which will return
false if the queue is full.
Another possible solution is to tailor the number of producers and consumers accordiingly.