Tag: producer-consumer

Explain Java BlockingQueue with Producer-Consumer thread example

Java BlockingQueue interface is used to implement producer consumer design pattern. This design pattern comes to solve common problem, in which producer and consumer threads use the same queue to pass over the information. In the Blocking Queue, producer will put elements and wait till space is available if queue is full and consumer will…

Read the full article

In a Producer & Consumer thread problem, producer thread has acquired the lock and multiple consumer threads are in wait pool, which consumer thread gets notified first, once producer thread calls notify?

Answer: The thread that it notifies depends on JVM implementation. We can’t really say which thread actually gets notified. It could be the first thread, it could be the last thread which went into the wait pool or it could be the highest priority thread. Most often the JVM implementation is as first thread goes…

Read the full article