public synchronized boolean readRequestImmediate(){
  if (currentWriters == 0 && writerLocks.size() == 0) {
    ++currentReaders;
    return true;
  }
  return false;
}

public synchronized boolean readRequestImmediate ( ) { if ( currentWriters == 0 && writerLocks . size ( ) == 0 ) { ++ currentReaders ; return true ; } return false ; }
this version of read ( ) requests read access and returns true if you get it . if it returns false , you may not safely read from the guarded resource . if it returns true , you should do the read , then call readdone in the normal way . here ' s an example : public void read ( ) { if ( lock . readrequestimmediate ( ) ) { try { / / do the read operation here } finally { lock . readdone ( ) ; } } else { / / couldn ' t read safely . }
