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

synchronized public boolean writeRequestImmediate ( ) { if ( writerLocks . size ( ) == 0 && currentReaders == 0 && currentWriters == 0 ) { ++ currentWriters ; return true ; } return false ; }
this version of the write request returns false immediately ( without blocking ) if any read or write operations are in progress and a write isn ' t safe ; otherwise , it returns true and acquires the resource . use it like this : public void write ( ) { if ( lock . writerequestimmediate ( ) ) { try { / / do the write operation here } finally { lock . writedone ( ) ; } } else { / / couldn ' t write safely . } }
