Here is the example.
class Factory {
Queue<Object> queue = new LinkedBlockingQueue<Object>();
public Object consume() {
queue.take();
}
public void produce() {
for (int i = 0; i < 2; i++) {
queue.put(new Object());
}
}
}
For example I have two threads which both called consume(). They are waiting for a producer to put something in the queue. My question is whether after a put() action a take() action happens, or is it possible for two put() actions to happen one after the other and only after that the waiting threads will return ?
Thank you.