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

Java Integration

Although Java is showing its age, it’s still one of the most widely used language. In this section, we’ll see that selecting a concurrency model does not force us down the path of language selection. We’ll reach out to the STM models right from within Java. We’ll have to endure some Java-induced verbosity and have to ensure immutability; however, it’s a breeze to use the STM API itself, as we’ll see.

Using Clojure STM in Java

We can use Clojure STM for Java quite easily because Ref and LockingTransaction are exposed as simple classes. The runInTransaction method takes as a parameter an instance that implements the Callable interface. So, wrapping code in a transaction is as simple as wrapping it in the Callable interface’s ...

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