A customized implementation of java.util.HashMap designed
to operate in a multithreaded environment where the large majority of
method calls are read-only, instead of structural changes. When operating
in "fast" mode, read calls are non-synchronized and write calls perform the
following steps:
- Clone the existing collection
- Perform the modification on the clone
- Replace the existing collection with the (modified) clone
When first created, objects of this class default to "slow" mode, where
all accesses of any type are synchronized but no cloning takes place. This
is appropriate for initially populating the collection, followed by a switch
to "fast" mode (by calling setFast(true) ) after initialization
is complete.
NOTE: If you are creating and accessing a
HashMap only within a single thread, you should use
java.util.HashMap directly (with no synchronization), for
maximum performance.
NOTE: This class is not cross-platform.
Using it may cause unexpected failures on some architectures.
It suffers from the same problems as the double-checked locking idiom.
In particular, the instruction that clones the internal collection and the
instruction that sets the internal reference to the clone can be executed
or perceived out-of-order. This means that any read operation might fail
unexpectedly, as it may be reading the state of the internal collection
before the internal collection is fully formed.
For more information on the double-checked locking idiom, see the
Double-Checked Locking Idiom Is Broken Declaration.
since: Commons Collections 1.0 version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: Craig R. McClanahan author: Stephen Colebourne |