Class AbstractWeakKeyBasedLockFactory<L>
java.lang.Object
org.craftercms.commons.concurrent.locks.AbstractWeakKeyBasedLockFactory<L>
- Type Parameters:
L
- the class of the lock
- All Implemented Interfaces:
KeyBasedLockFactory<L>
- Direct Known Subclasses:
WeakKeyBasedReentrantLockFactory
public abstract class AbstractWeakKeyBasedLockFactory<L>
extends Object
implements KeyBasedLockFactory<L>
Abstract implementation of
KeyBasedLockFactory
that uses a WeakHashMap
to store the locks. When
code using a lock is done, and there are no more references to the lock, the lock is automatically removed from
the map.- Since:
- 3.1.5
- Author:
- avasquez
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
locks
-
-
Constructor Details
-
AbstractWeakKeyBasedLockFactory
protected AbstractWeakKeyBasedLockFactory()
-
-
Method Details
-
getLock
Description copied from interface:KeyBasedLockFactory
Returns a lock for the specified key. Implementations will normally do the following: when the first thread calls this method with a key, a new lock is created and returned. When a second, third and so on concurrent thread tries to get a lock for the same key, the first lock is returned, thus allowing synchronization based on the key.- Specified by:
getLock
in interfaceKeyBasedLockFactory<L>
- Parameters:
key
- the key associated with the lock- Returns:
- the lock
-
newLock
-