Scalable Collections

Collections like Vector that originally came with Java gave us thread safety at the cost of performance. All of our accesses, irrespective of the need, were thread safe but slow.

Later collections like ArrayList provided speed but lacked thread safety. Again, we traded performance for thread safety when we used one of the synchronized wrappers of the collections, like using the synchronizedList of Collections.

The bottom line is that we had to pick between thread safety and performance. Java 5’s java.util.concurrent changed all that with concurrent data structures like ConcurrentHashMap and ConcurrentLinkedQueue. These collections provide better performance, at the expense of space, but we have to be willing to accept ...

Get Programming Concurrency on the JVM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.