Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The CopyOnWriteArrayList data structure implements all mutating operations by making a fresh copy of the underlying array. It is fully thread-safe, and is optimized for cases where traversal operations vastly outnumber mutations. Note that traversals of such lists always see the list in the state it had at the creation of the iterator (or enhanced for loop); subsequent modifications of the list are invisible to an ongoing traversal. Consequently, this solution is inappropriate when mutations of the list are frequent or when new values should be reflected in ongoing traversals.

Code Block
bgColor#ccccff
List<Widget> widgetList = new CopyOnWriteArrayList<Widget>();

pubic void widgetOperation() {
  for (Widget w : widgetList) {
    doSomething(w);
  }
}

...