public void writeRequest(){
  Object lock=new Object();
synchronized (lock) {
synchronized (this) {
      boolean goAheadWithWrite=writerLocks.size() == 0 && currentReaders == 0 && currentWriters == 0;
      if (goAheadWithWrite) {
        ++currentWriters;
        return;
      }
      writerLocks.addLast(lock);
    }
    try {
      lock.wait();
    }
 catch (    InterruptedException e) {
    }
  }
}

public void writeRequest ( ) { Object lock = new Object ( ) ; synchronized ( lock ) { synchronized ( this ) { boolean goAheadWithWrite = writerLocks . size ( ) == 0 && currentReaders == 0 && currentWriters == 0 ; if ( goAheadWithWrite ) { ++ currentWriters ; return ; } writerLocks . addLast ( lock ) ; } try { lock . wait ( ) ; } catch ( InterruptedException e ) { } } }
request the write lock . block until a write operation can be performed safely . write requests are guaranteed to be executed in the order received . pending read requests take precedence over all write requests . this call must be followed by a call to writedone ( ) when the write operation completes .
