com.bigdata.concurrent
Class NamedLock<T>
java.lang.Object
com.bigdata.concurrent.NamedLock<T>
- Type Parameters:
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
A factory for named 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.
- Version:
- $Id: NamedLock.java 2265 2009-10-26 12:51:06Z thompsonbry $
- Author:
- Bryan Thompson
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NamedLock
public NamedLock()
lockFactory
protected Lock lockFactory(T name)
- Return the canonical instance of the lock for a named resource.
- Parameters:
name - The name.
- Returns:
- The canonical instance of the lock for that name.
acquireLock
public Lock acquireLock(T name)
- Block until the
Lock for the named resource is available, then
Lock.lock() the Lock and return the locked Lock.
- Parameters:
name - The name of the resource whose Lock is desired.
- Returns:
- The
Lock. It will have already been Lock.lock()ed.
acquireLock
public Lock acquireLock(T name,
long timeout,
TimeUnit unit)
throws InterruptedException,
TimeoutException
- Throws:
InterruptedException
TimeoutException
Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.