public synchronized void lock ( ) { if ( tc . isEntryEnabled ( ) ) SibTr . entry ( tc , "lock" , this ) ; boolean interrupted = false ; // Attempt to get a lock on the mutex. // if we fail, then that is because the lock // must be held exclusively. while ( ! tryLock ( ) ) try { // Wait for 1 second then try again. if ( tc . isDebugEnabled ( ) ) SibTr . debug ( tc , "Waiting for lock" ) ; wait ( 1000 ) ; } catch ( InterruptedException e ) { // No FFDC code needed interrupted = true ; } if ( interrupted ) Thread . currentThread ( ) . interrupt ( ) ; if ( tc . isEntryEnabled ( ) ) SibTr . exit ( tc , "lock" ) ; }
This method allows multiple lockers to lock the same mutex until the lock exclusive is called . Then all lock requesters have to wait until the exclusive lock is released .