Package org.pipservices3.components.lock
Class MemoryLock
java.lang.Object
org.pipservices3.components.lock.Lock
org.pipservices3.components.lock.MemoryLock
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable,org.pipservices3.commons.config.IReconfigurable,ILock
Lock that is used to synchronize execution within one process using shared memory.
Remember: This implementation is not suitable for synchronization of distributed processes.
### Configuration parameters ###
-
options:
- - retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
MemoryLock lock = new MemoryLock();
try {
// Processing...
}
finally {
lock.releaseLock("123", "key1");
// Continue...
});
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidreleaseLock(String correlationId, String key) Releases the lock with the given key.booleantryAcquireLock(String correlationId, String key, int ttl) Makes a single attempt to acquire a lock by its key.Methods inherited from class org.pipservices3.components.lock.Lock
acquireLock, configure
-
Constructor Details
-
MemoryLock
public MemoryLock()
-
-
Method Details
-
tryAcquireLock
Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.- Specified by:
tryAcquireLockin interfaceILock- Specified by:
tryAcquireLockin classLock- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.key- a unique lock key to acquire.ttl- a lock timeout (time to live) in milliseconds.- Returns:
trueif the lock was acquired andfalseotherwise.
-
releaseLock
Releases the lock with the given key.- Specified by:
releaseLockin interfaceILock- Specified by:
releaseLockin classLock- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.key- a unique lock key to release.
-