O'Reilly logo

Programming Concurrency on the JVM by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required