Skip to content
Ameen Abozaid
Planned lessonMID-005-L03

Blocking queues and producer-consumer

  • Lesson 3 of 5
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

build a bounded pipeline with backpressure.

Planned topics

  • BlockingQueue: put blocks when full, take blocks when empty; offer/poll accept timeouts.
  • ArrayBlockingQueue is bounded; LinkedBlockingQueue is unbounded unless given a capacity.
  • A bounded queue gives backpressure: fast producers slow down instead of exhausting memory.
  • Stopping consumers: send a poison pill, or interrupt the workers.
  • Choose queue size from latency tolerance, not "large to be safe".
Draft outline details

Demonstration

java
BlockingQueue<OrderEvent> q = new ArrayBlockingQueue<>(1_000);
// producer: q.put(event);   consumer: var e = q.take();

Check your understanding

What happens when a producer calls put on a full queue?

Show answer

It blocks until space is free.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.