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

Collections and Transactions

As we work through the examples, it’s easy to forget that the values we’re dealing with are, and should be, immutable. Only the identity is mutable, not the state value. Although STM makes life easy, it can be a challenge to ensure good performance while maintaining immutability.

Take the first step to ensure immutability. Make value classes final, and mark all their fields final (vals in Scala). Then transitively ensure that the classes for each field the values use are immutable as well. It should be first nature to make fields and classes final—this is the first step toward avoiding concurrency issues.

Although immutability will make code better and safer, one prominent reason that programmers are reluctant ...

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