Skip to content
Ameen Abozaid
Planned lessonMID-005-L04

Copy-on-write structures

  • Lesson 4 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

know when CopyOnWriteArrayList fits.

Planned topics

  • Every write copies the whole array; reads need no lock and iterate a stable snapshot.
  • Fits read-mostly, small lists such as listeners or configuration.
  • Hurts with frequent writes or large lists (copy cost, garbage).
  • Iterators do not reflect later changes and do not support remove.
  • For frequent writes use other structures.
Draft outline details

Demonstration

a list of 5 event listeners read on every request, changed a few times a day: a good fit.

Check your understanding

Is it a good choice for a 1 million entry list updated every second?

Show answer

No; each write copies the whole array.

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.