T - The generic type for the "name". This MUST implement hashCode()
and equals() since the instances of this type will serve as keys
in a Map.public class NamedLock<T> extends Object
Locks. A simple Lock manages access to a
single resource. However, a NamedLock manages access to the members
of a set of named resources. This is more efficient when the latency of the
operation once the lock is acquired is significant, e.g., an RMI call or a
disk IO.
The locks are stored in a WeakHashMap so that they will be garbage
collected if there are no threads waiting in the queue for a given named
lock.
| Constructor and Description |
|---|
NamedLock() |
| Modifier and Type | Method and Description |
|---|---|
Lock |
acquireLock(T name)
Block until the
Lock for the named resource is available, then
Lock.lock() the Lock and return the locked Lock. |
Lock |
acquireLock(T name,
long timeout,
TimeUnit unit) |
protected Lock |
lockFactory(T name)
Return the canonical instance of the lock for a named resource.
|
protected Lock lockFactory(T name)
name - The name.public Lock acquireLock(T name)
Lock for the named resource is available, then
Lock.lock() the Lock and return the locked Lock.name - The name of the resource whose Lock is desired.Lock. It will have already been Lock.lock()ed.public Lock acquireLock(T name, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException
InterruptedExceptionTimeoutExceptionCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.