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. 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.Constructor and Description |
---|
PessimisticLockFactory()
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 . |
public PessimisticLockFactory()
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 thrownCopyright © 2010–2018. All rights reserved.