Package co.stateful
Class Atomic<T>
- java.lang.Object
-
- co.stateful.Atomic<T>
-
- Type Parameters:
T
- Type of result
- All Implemented Interfaces:
Callable<T>
@Loggable(1) public final class Atomic<T> extends Object implements Callable<T>
Atomic block of code.This class runs your
Callable
in a concurrent thread-safe manner, using a lock from Stateful.co. For example:Callable<String> origin = new Callable<String>() { @Override public String call() { // fetch it from a thread-critical resource // and return } }; Lock lock = new RtSttc(new URN("urn:github:12345"), "token") .locks().lock("test"); String result = new Atomic<String>(origin, lock).call();
If you want to use
Runnable
instead, try static methodExecutors.callable(Runnable)
. If you want to avoid checked exceptions, usecallQuietly()
.- Since:
- 0.6
- See Also:
- Atomic Counters at Stateful.co, Synchronization Between Nodes
-
-
Constructor Summary
Constructors Constructor Description Atomic(Callable<T> clbl, Lock lck)
Public ctor (default maximum waiting time of five minutes).Atomic(Callable<T> clbl, Lock lck, String lbl)
Public ctor (default maximum waiting time of five minutes).Atomic(Callable<T> clbl, Lock lck, String lbl, long maximum)
Public ctor.
-
-
-
Constructor Detail
-
Atomic
public Atomic(Callable<T> clbl, Lock lck)
Public ctor (default maximum waiting time of five minutes).- Parameters:
clbl
- Callable to uselck
- Lock to use
-
Atomic
public Atomic(Callable<T> clbl, Lock lck, String lbl)
Public ctor (default maximum waiting time of five minutes).- Parameters:
clbl
- Callable to uselck
- Lock to uselbl
- Label to use for locking and unlocking (can be empty)
-
-