Choices in Scala

Scala is a statically typed language on the JVM, which bridges object-oriented style and functional style of programming. We have quite a few options to make use of STM from this highly expressive language. It’s likely that we’d lean toward the Akka solution because the Scala API it provides will be the most fluent. However, if we’re on a multilanguage project that’s already using Clojure STM, nothing stops us from using that from Scala. Let’s explore using Clojure STM here.

Using Clojure STM in Scala

Using Clojure STM in Scala is going to follow along pretty much the lines of Java. We can use the Ref class and the runInTransaction method of the LockingTransaction class. We create an instance that implements Callable to wrap ...

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.