Module net.javacrumbs.shedlock.core
Package net.javacrumbs.shedlock.support
Class StorageBasedLockProvider
java.lang.Object
net.javacrumbs.shedlock.support.StorageBasedLockProvider
- All Implemented Interfaces:
ExtensibleLockProvider,LockProvider
Distributed lock using abstract storage
It uses a table/collection that contains ID = lock name and a field locked_until.
- Attempts to insert a new lock record. As an optimization, we keep in-memory track of created lock records. If the record has been inserted, returns lock.
- We will try to update lock record using filter ID == name AND lock_until <= now
- If the update succeeded (1 updated row/document), we have the lock. If the update failed (0 updated documents) somebody else holds the lock
- When unlocking, lock_until is set to now.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStorageBasedLockProvider(StorageAccessor storageAccessor) -
Method Summary
Modifier and TypeMethodDescriptionvoidClears cache of existing lock records.protected booleandoLock(LockConfiguration lockConfiguration) Sets lockUntil according to LockConfiguration if current lockUntil <= nowlock(LockConfiguration lockConfiguration)
-
Constructor Details
-
StorageBasedLockProvider
-
-
Method Details
-
clearCache
public void clearCache()Clears cache of existing lock records. -
lock
- Specified by:
lockin interfaceLockProvider- Returns:
- If empty optional has been returned, lock could not be acquired. The lock has to be released by the callee.
-
doLock
Sets lockUntil according to LockConfiguration if current lockUntil <= now
-