com.yworks.yfiles.server.tiles.support
Class ReadWriteLock

java.lang.Object
  extended bycom.yworks.yfiles.server.tiles.support.ReadWriteLock

public class ReadWriteLock
extends Object

A ReadWriteLock instance can be used to manage read and write access such that simultaneous read access is allowed, but only a single thread is allowed to write. This implementation allows reentrant calls, i.e., threads that have already acquired a read or write lock can call readLock() or writeLock() again. The yFiles AJAX Servlets make heavy use of the read/write lock mechanism in order to prevent concurrent modifications to graph instances while being able to serve multiple simultaneous read requests when the graph is not modified. To obtain read/write locks for a graph instance, the corresponding convenience methods provided by class BaseServlet can be used. Threads that acquire a read or write lock have to make sure that the locks are properly released after the read or write operations:

 BaseServlet.readLock(graph);
 try {
   // read graph, e.g. iterate over the graph's nodes
 } finally {
   BaseServlet.unlockRead(graph)
 }
 

See Also:
BaseServlet.readLock(y.view.Graph2D), BaseServlet.unlockRead(y.view.Graph2D), BaseServlet.writeLock(y.view.Graph2D), BaseServlet.unlockWrite(y.view.Graph2D)

Constructor Summary
ReadWriteLock()
           
 
Method Summary
protected  void onWriteFinished()
          Called when unlockWrite() has been called for the last active writer.
 void readLock()
          Acquire a read lock.
 void unlockRead()
          Release a read lock that has been acquired using readLock().
 void unlockWrite()
          Release a write lock that has been acquired using writeLock().
 void writeLock()
          Acquire a write lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadWriteLock

public ReadWriteLock()
Method Detail

readLock

public void readLock()
Acquire a read lock. If another thread has currently acquired the write lock, the calling thread waits until the write lock has been unlocked and there are no pending write requests. The read lock has to be released using unlockRead():
 readWriteLock.readLock();
 try {
   // read
 } finally {
   readWriteLock.unlockRead()
 }
 


unlockRead

public void unlockRead()
Release a read lock that has been acquired using readLock().

See Also:
readLock()

writeLock

public void writeLock()
Acquire a write lock. The write lock will be acquired if If another thread currently has the read or write lock, the calling thread waits until the write lock can be acquired. The write lock has to be released using unlockWrite():
 readWriteLock.writeLock();
 try {
   // write
 } finally {
   readWriteLock.unlockWrite()
 }
 


unlockWrite

public void unlockWrite()
Release a write lock that has been acquired using writeLock().

See Also:
writeLock()

onWriteFinished

protected void onWriteFinished()
Called when unlockWrite() has been called for the last active writer.



Copyright © 2006-2013 yWorks GmbH. All rights reserved