Multiverse is a Java 1.6+ based Software Transactional Memory (STM) framework that supports seamless integration with the Java language using annotations.
Move
At the begin of Februari Multiverse will be moved to Codehaus and there also is a new website, including a thorough reference manual and Multiverse 0.4 will be released. The site in progress can be found here:
http://multiverse.codehaus.org/overview.html
Multiverse and the Java language
Multiverse supports multiple programming models. The simplest model for Java code is based on POJO's combined with annotations. By placing an AtomicObject annotation above a POJO, or by placing an AtomicMethod annotation above a method, multiverse will make sure that all changes made happen atomic (so all of them or non of them) and are completely isolated (so no concurrency problems).
This is an example of a stack:
@AtomicObject
public class Stack<E>{
private Node<E> head;
public void push(E item) {
if (item == null) {
throw new NullPointerException();
}
head = new Node(item, head);
}
public E peek() {
return head == null ? null : head.value;
}
public E pop() {
if (head == null){
retry();
}
return removeTopItem();
}
private E removeTopItem() {
Node<E> oldHead = head;
head = head.parent;
return oldHead.value;
}
public int size() {
return head == null ? 0 : head.size();
}
public boolean isEmpty() {
return size() == 0;
}
public static class Node<E> {
final E value;
final Node parent;
final int size;
Node(E value, Node prev) {
this.value = value;
this.parent = prev;
this.size = parent == null ? 1 : prev.size+1;
}
int size() {
return size;
}
}
}As you can see there is no explicit need for volatile variables, synchronized blocks/locks and wait/notify mechanisms or conditions even though this class can safely be shared between threads; it even supports blocking operation!
For more information about how to use Multiverse, see Introduction to annotation based configuration.
For a list of features (and planned features) check the Wiki.
Multiverse not limited to the Java language
Multiverse isn't limited to the Java language; it can perfectly be used with other JVM-based languages like Scala/Groovy/JRuby etc as long as they are able to make use of a managed reference (so the annotations and instrumentation can be skipped) At the moment Multiverse is used in the Akka project; a distributed actors library written in Scala.
If you think that your project could benefit from an STM, please send an email to the mailinglist.