public class PessimisticLockFactory extends Object implements LockFactory
LockFactory
that uses a pessimistic locking strategy. Calls to
obtainLock(java.lang.String)
will block until a lock could be obtained or back off limit is reached, based on the
settings provided, by throwing an exception. The latter will cause the command to fail, but will allow
the calling thread to be freed. If a lock is obtained by a thread, that thread has guaranteed unique access.
Each thread can hold the same lock multiple times. The lock will only be released for other threads when the lock
has been released as many times as it was obtained.
This lock can be used to ensure thread safe access to a number of objects, such as Aggregates and Sagas.Modifier and Type | Class and Description |
---|---|
static class |
PessimisticLockFactory.Builder
Builder class for the
PessimisticLockFactory . |
Modifier | Constructor and Description |
---|---|
protected |
PessimisticLockFactory(PessimisticLockFactory.Builder builder)
Creates an instance of the lock factory using the given
builder containing the configuration properties
to use. |
Modifier and Type | Method and Description |
---|---|
static PessimisticLockFactory.Builder |
builder()
Creates a builder to construct an instance of this LockFactory.
|
Lock |
obtainLock(String identifier)
Obtain a lock for a resource identified by the given
identifier . |
static PessimisticLockFactory |
usingDefaults()
Creates an instance using default values, as defined in the properties of the
PessimisticLockFactory.Builder . |
protected PessimisticLockFactory(PessimisticLockFactory.Builder builder)
builder
containing the configuration properties
to use.builder
- The building containing the configuration properties to usepublic static PessimisticLockFactory.Builder builder()
public static PessimisticLockFactory usingDefaults()
PessimisticLockFactory.Builder
.public Lock obtainLock(String identifier)
identifier
. This method will block until a
lock was successfully obtained.
Note: when an exception occurs during the locking process, the lock may or may not have been allocated.obtainLock
in interface LockFactory
identifier
- the identifier of the lock to obtain.IllegalMonitorStateException
is thrown
IllegalArgumentException
is thrown when identifier is nullCopyright © 2010–2022. All rights reserved.