Groovy is a good choice among languages if we’re looking for easy metaprogramming and dynamic typing while preserving Java semantics. In this section, we’ll use the Clojure STM and the Multiverse STM through Akka in Groovy Apps. To use Multiverse directly, refer to the Multiverse documentation.
Using Clojure STM is as simple as using instances of clojure.lang.Ref for managed references and invoking the runInTransaction method of LockingTransaction to place a piece of code in a transaction. Let’s give it a shot using the account transfer example. Create a class called Account to hold a managed reference to its immutable state, represented by the variable currentBalance: