Versions Compared

Key

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

...

Programmers sometimes assume that using a thread-safe Collection does not require explicit synchronization which is a misleading thought. It follows that using a thread-safe Collection by itself does not ensure program correctness unless special care is taken to ensure that the client performs all related and independently atomic operations, as one atomic operation. For example, the standard thread-safe API may not provide a method to find a particular person's record in a Hashtable and update the corresponding payroll information. In such cases, a custom thread-safe method must be designed and used. This guideline shows the need of such a method that performs a group of independently atomic operations as one atomic operation, and also suggests techniques for incorporating the method using a custom API. The custom API is essential because the standard API cannot be changed without breaking other code that relies on it.

This guideline applies to all uses of Collection classes including the thread-safe Hashtable class. Enumerations of the objects of a Collection and iterators also require explicit synchronization on the Collection object or any single lock object.

...