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 ofKeyBasedLockFactory
that uses aWeakHashMap
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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractWeakKeyBasedLockFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description L
getLock(Object key)
Returns a lock for the specified key.protected abstract L
newLock()
-
-
-
Method Detail
-
getLock
public L getLock(Object key)
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
protected abstract L newLock()
-
-