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
PessimisticLockFactory.BackoffParameters
, 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.
Back off properties with respect to acquiring locks can be configured through the PessimisticLockFactory.BackoffParameters
.
Modifier and Type | Class and Description |
---|---|
static class |
PessimisticLockFactory.BackoffParameters
There are 3 values:
|
Constructor and Description |
---|
PessimisticLockFactory()
Deprecated.
|
PessimisticLockFactory(PessimisticLockFactory.BackoffParameters backoffParameters)
Creates a new IdentifierBasedLock instance.
|
Modifier and Type | Method and Description |
---|---|
Lock |
obtainLock(String identifier)
Obtain a lock for a resource identified by the given
identifier . |
@Deprecated public PessimisticLockFactory()
public PessimisticLockFactory(PessimisticLockFactory.BackoffParameters backoffParameters)
PessimisticLockFactory.BackoffParameters
backoffParameters
- back off policy configurationpublic 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 thrownCopyright © 2010–2018. All rights reserved.