public void getSharedLock ( int requestId ) { if ( tc . isEntryEnabled ( ) ) Tr . entry ( tc , "getSharedLock" , new Object [ ] { this , new Integer ( requestId ) } ) ; Thread currentThread = Thread . currentThread ( ) ; Integer count = null ; synchronized ( this ) { // If this thread does not have any existing shared locks and there is a thread waiting to get the exclusive // lock or a thread (other than this thread) who already holds the exclusive lock then we will have to wait // until the exclusive lock is eventually dropped before granting the shared lock. if ( ( ! _sharedThreads . containsKey ( currentThread ) ) && ( ( _threadRequestingExclusiveLock != null ) || ( ( _threadHoldingExclusiveLock != null ) && ( ! _threadHoldingExclusiveLock . equals ( currentThread ) ) ) ) ) { while ( ( _threadHoldingExclusiveLock != null ) || ( _threadRequestingExclusiveLock != null ) ) { if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " is waiting for the exclusive lock to be released" ) ; try { if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " waiting.." ) ; this . wait ( ) ; } catch ( java . lang . InterruptedException exc ) { FFDCFilter . processException ( exc , "com.ibm.ws.recoverylog.spi.Lock.getSharedLock" , "180" , this ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " was interrupted unexpectedly during wait. Retesting condition" ) ; // This exception is recieved if another thread interrupts this thread by calling this threads // Thread.interrupt method. The Lock class does not use this mechanism for breaking out of the // wait call - it uses notifyAll to wake up all waiting threads. This exception should never // be generated. If for some reason it is called then ignore it and start to wait again. } } if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " is has detected that the exclusive lock has been released" ) ; } count = ( Integer ) _sharedThreads . get ( currentThread ) ; if ( count == null ) { count = new Integer ( 1 ) ; } else { count = new Integer ( count . intValue ( ) + 1 ) ; } _sharedThreads . put ( currentThread , count ) ; } if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Count: " + count ) ; if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "getSharedLock" ) ; }
This method is called to request a shared lock . There are conditions under which a shared lock cannot be granted and this method will block until no such conditions apply . When the method returns the thread has been granted an additional shared lock . A single thread may hold any number of shared locks but the number of requests must be matched by an equal number of releases .