• 0.15

Locks at Stateful.co

For example, you need a lock available online and shared among multiple processes running on different nodes in the network. Here is how you do it in Java, using this SDK:

import co.stateful.Counter;
import co.stateful.Counters;
import co.stateful.Sttc;
import co.stateful.RtSttc;
import com.jcabi.urn.URN;
public class Main {
  public static void main(String... args) throws Exception {
    Sttc sttc = new RtSttc(
      new URN("urn:github:526301"),
      "9FF3-41E0-73FB-F900"
    );
    Lock lock = sttc.locks().get("my-test-lock");
    new Atomic<Void>(
      new Callable<Void>() {
        @Override
        public Void call() {
          System.out.println("this call is synchronized");
        }
      },
      lock
    ).call();
  }
}

If you want to use Runnable instead, try static method java.util.concurrent.Executors#callable(Runnable). If you want to avoid checked exceptions, try Callable from tempusfugitlibrary.org.