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 NamedReadWriteLock<T> extends Object
ReadWriteLock
s. A simple ReadWriteLock
manages access to a single resource. However, a NamedReadWriteLock
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 |
---|
NamedReadWriteLock() |
Modifier and Type | Method and Description |
---|---|
Lock |
acquireReadLock(T name)
Block until the
ReentrantReadWriteLock.ReadLock for the named resource is available,
then Lock.lock() the Lock and returns the Lock . |
Lock |
acquireReadLock(T name,
long timeout,
TimeUnit unit) |
Lock |
acquireWriteLock(T name) |
Lock |
acquireWriteLock(T name,
long timeout,
TimeUnit unit) |
protected ReentrantReadWriteLock |
lockFactory(T name)
Return the canonical instance of the lock for a named resource.
|
protected ReentrantReadWriteLock lockFactory(T name)
name
- The name.public Lock acquireReadLock(T name)
ReentrantReadWriteLock.ReadLock
for the named resource is available,
then Lock.lock()
the Lock
and returns the Lock
.name
- The name of the resource whose Lock
is desired.Lock
. It will have already been Lock.lock()
ed.public Lock acquireReadLock(T name, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException
InterruptedException
TimeoutException
public Lock acquireWriteLock(T name, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException
InterruptedException
TimeoutException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.