Contact Us

[email protected]

Most of the collections in the java.util package are not thread-safe—executing concurrent operations on them is courting disaster. Exceptions to this are the legacy Vector and Hashtable classes, but these use a single lock, allowing only one thread at a time to execute an operation on the collection while other threads are blocked. The synchronized collections created by methods in the java.util.Collections class are not much better, as they are just thread-safe wrappers around a backing collection, again providing only mutually exclusive operations on the backing collection. However, the concurrent collections provided by the java.util.concurrent package use special-purpose locking mechanisms to enable multiple threads to operate concurrently, without explicit locking on the collection and with minimal contention. The concurrent collections offer greater flexibility and higher scalability compared to the collections in the java.util package, when concurrent access is crucial for multiple threads sharing objects stored in a collection.