com.boylesoftware.cb2.util
Class AccessGuard

java.lang.Object
  extended bycom.boylesoftware.cb2.util.AccessGuard

public final class AccessGuard
extends java.lang.Object

This class provides service for synchronizing access to a guarded object from multiple concurrent threads. Each thread may be either a reader or a writer. When a reader has started working with the target object by calling startReading() method any writer trying to call startWriting() will wait until all readers free the object by calling endReading(), while readers continue to be able register with startReading() calls. When a writer gets access to the object by calling startWriting() any other reader or writer will wait until the writer frees the object by calling endWriting().

If your code can throw an exception it is recommended to have "end" methods calls in finally blocks.

Version:
$Id: AccessGuard.java,v 1.1 2003/04/22 17:34:18 levahim Exp $
Author:
Lev Himmelfarb

Constructor Summary
AccessGuard()
          Constructs a guard.
 
Method Summary
 void endReading()
          Unregisters a reader.
 void endWriting()
          Unregisters a writer.
 void startReading()
          Registers a reader.
 void startWriting()
          Registers a writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AccessGuard

public AccessGuard()
Constructs a guard. You need one instance of the guard per each target object instance.

Method Detail

startReading

public void startReading()
Registers a reader.


endReading

public void endReading()
Unregisters a reader.


startWriting

public void startWriting()
Registers a writer.


endWriting

public void endWriting()
Unregisters a writer.



Copyright © 2002,2003,2004 - Boyle Software, Inc.