com.ibm.commons.util
Class ThreadLockManager

java.lang.Object
  extended by com.ibm.commons.util.ThreadLockManager

public class ThreadLockManager
extends java.lang.Object

Read write lock acquisition.

Locking strategies can be defined by overriding some of the protected methods (who has priority, how many concurrent thread can run simultaneously...). Also note that JRE 5 now has a concurrent package which can be used to replace this class.

Inspired from 'Concurrent programming in Java, 2nd edition'


Field Summary
protected  int activeReaders
           
protected  int activeWriters
           
protected  int waitingReaders
           
protected  int waitingWriters
           
 
Constructor Summary
ThreadLockManager()
           
 
Method Summary
protected  void afterRead(java.lang.Object param)
           
protected  void afterWrite(java.lang.Object param)
           
protected  boolean allowReader(java.lang.Object param)
           
protected  boolean allowWriter(java.lang.Object param)
           
protected  void beforeRead(java.lang.Object param)
           
protected  void beforeWrite(java.lang.Object param)
           
protected  void doRead()
           
protected  void doWrite()
           
 ThreadLock getReadLock()
          Get a lock used to read data.
 ThreadLock getReadLock(java.lang.Object param)
          Get a lock used to read data.
 ThreadLock getWriteLock()
          Get a lock used to write data.
 ThreadLock getWriteLock(java.lang.Object param)
          Get a lock used to write data.
 void read()
           
 void read(java.lang.Object param)
           
protected  boolean tryBeforeRead(java.lang.Object param)
           
protected  boolean tryBeforeWrite(java.lang.Object param)
           
protected  void waitForRead(java.lang.Object param)
           
protected  void waitForWrite(java.lang.Object param)
           
 void write()
           
 void write(java.lang.Object param)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeReaders

protected int activeReaders

activeWriters

protected int activeWriters

waitingReaders

protected int waitingReaders

waitingWriters

protected int waitingWriters
Constructor Detail

ThreadLockManager

public ThreadLockManager()
Method Detail

allowReader

protected boolean allowReader(java.lang.Object param)

allowWriter

protected boolean allowWriter(java.lang.Object param)

beforeRead

protected void beforeRead(java.lang.Object param)
                   throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

waitForRead

protected void waitForRead(java.lang.Object param)
                    throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

tryBeforeRead

protected boolean tryBeforeRead(java.lang.Object param)
                         throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

afterRead

protected void afterRead(java.lang.Object param)

beforeWrite

protected void beforeWrite(java.lang.Object param)
                    throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

waitForWrite

protected void waitForWrite(java.lang.Object param)
                     throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

tryBeforeWrite

protected boolean tryBeforeWrite(java.lang.Object param)
                          throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

afterWrite

protected void afterWrite(java.lang.Object param)

read

public void read()
          throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

read

public void read(java.lang.Object param)
          throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

write

public void write()
           throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

write

public void write(java.lang.Object param)
           throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

doRead

protected void doRead()

doWrite

protected void doWrite()

getReadLock

public ThreadLock getReadLock()
Get a lock used to read data.


getReadLock

public ThreadLock getReadLock(java.lang.Object param)
Get a lock used to read data.


getWriteLock

public ThreadLock getWriteLock()
Get a lock used to write data.


getWriteLock

public ThreadLock getWriteLock(java.lang.Object param)
Get a lock used to write data.