Package com.yahoo.concurrent
Class Locks<TYPE>
java.lang.Object
com.yahoo.concurrent.Locks<TYPE>
Holds a map of locks indexed on keys of a given type.
This is suitable in cases where exclusive access should be granted to any one of a set of keyed objects and
there is a finite collection of keyed objects.
The returned locks are reentrant (i.e the owning thread may call lock multiple times) and auto-closable.
Typical use is
try (Lock lock = locks.lock(id)) {
exclusive use of the object with key id
}
- Author:
- bratseth
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
Locks
Create locks with a default timeout
-
-
Method Details
-
lock
Locks key. This will block until the key is acquired or the default timeout is reached. -
lock
Locks key. This will block until the key is acquired or the timeout is reached. Users of this must close any lock acquired.- Parameters:
key
- the key to lock- Returns:
- the acquired lock
- Throws:
UncheckedTimeoutException
- if the lock could not be acquired within the timeout
-