org.sourceforge.jemm.util
Class LockManager<K>

java.lang.Object
  extended by org.sourceforge.jemm.util.LockManager<K>
Type Parameters:
K - The type of ID to use as the lock key

public class LockManager<K>
extends java.lang.Object

A generic mutual exclusion lock manager for locks on arbitrary ids. From the callers point of view the lock always exists. Internally this lock may be created on the fly as needed. If two clients attempt to acquire the same lock one will end up holding the lock and one will be blocked until the lock is freed by the first. From an administration point of view, old, unused locks may be reclaimed using the clearUnusedLocks() method. Note synchronisation blocks are not needed, as per Java 6 Semaphore javadoc comment: 'Memory consistency effects: Actions in a thread prior to calling a "release" method such as release() happen-before actions following a successful "acquire" method such as acquire() in another thread. '

Author:
Rory Graves

Field Summary
static long ERROR_TIMEOUT
           
protected  org.sourceforge.jemm.util.LockManager.LockStore lockStore
           
 
Constructor Summary
LockManager()
           
 
Method Summary
 void acquire(K lockId)
          Acquire the lock on lock 'lockId', if necessary blocking until the lock becomes available.
 java.lang.Thread getLockHolder(K id)
           
 int noLocksHeld()
           
 void release(K lockId)
          Release the lock on 'lockId'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_TIMEOUT

public static final long ERROR_TIMEOUT
See Also:
Constant Field Values

lockStore

protected org.sourceforge.jemm.util.LockManager.LockStore lockStore
Constructor Detail

LockManager

public LockManager()
Method Detail

acquire

public void acquire(K lockId)
Acquire the lock on lock 'lockId', if necessary blocking until the lock becomes available.

Parameters:
lockId - The id of the lock to acquire
Throws:
java.lang.InterruptedException

release

public void release(K lockId)
Release the lock on 'lockId'

Parameters:
lockId - The lockId of the lock to release.

noLocksHeld

public int noLocksHeld()

getLockHolder

public java.lang.Thread getLockHolder(K id)


Copyright © 2009. All Rights Reserved.