pekko/akka-stm/src/test/java/akka/stm/example/CounterExample.java

26 lines
661 B
Java
Raw Normal View History

2010-11-12 16:09:31 +13:00
package akka.stm.example;
2010-08-16 11:38:39 +12:00
2010-11-06 19:11:56 +13:00
import akka.stm.*;
2010-08-16 11:38:39 +12:00
public class CounterExample {
final static Ref<Integer> ref = new Ref<Integer>(0);
public static int counter() {
return new Atomic<Integer>() {
public Integer atomically() {
int inc = ref.get() + 1;
ref.set(inc);
return inc;
}
}.execute();
}
public static void main(String[] args) {
System.out.println();
System.out.println("Counter example");
System.out.println();
System.out.println("counter 1: " + counter());
System.out.println("counter 2: " + counter());
}
}