public boolean attemptExclusiveLock() throws HoldingExclusiveLockException
  {
    if (tc.isEntryEnabled()) Tr.entry(tc, "attemptExclusiveLock",this);

    boolean obtained = false;

    Thread currentThread = Thread.currentThread();

    synchronized(this)
    {
      if ((_threadHoldingExclusiveLock != null) && (_threadHoldingExclusiveLock.equals(currentThread)))
      {
        // This thread already holds the exclusive lock. A thread is not allowed to request the exclusive
        // lock again if it already holds it.
        if (tc.isEntryEnabled()) Tr.exit(tc, "attemptExclusiveLock", "HoldingExclusiveLockException");
        throw new HoldingExclusiveLockException();
      }
      else
      {
        if ((_threadHoldingExclusiveLock != null) || (_threadRequestingExclusiveLock != null))
        {
          // Another thread is either holding or requesting the exclusive lock. This thread will 
          // not be granted the lock and will return with 'false'. Before returning, this
          // thread will wait for the exclusive lock to be released.

          // Before we start waiting for the exclusive lock release event, we must ensure we
          // "suspend" any shared locks this thread currently holds. If this is not done, then
          // these shared locks will prevent an exclusive lock from being granted and
          // hence deadlock the system. When the waiting is complete these shared locks will be
          // restored. Notify other waiting threads so that they know that some more
          // shared locks have been removed.
          Integer suspendedSharedLockCount = (Integer)_sharedThreads.get(currentThread);
          _sharedThreads.remove(currentThread);
          this.notifyAll();
     
          if (tc.isDebugEnabled()) Tr.debug(tc, "Thread " + Integer.toHexString(currentThread.hashCode()) + " is waiting for the exclusive lock to be released");

          while ((_threadHoldingExclusiveLock != null) || (_threadRequestingExclusiveLock != null))
          {
            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.attemptExclusiveLock", "325", 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()) + " has detected that the exclusive lock has been released");

          // Resume the shared locks that were suspened prior to the wait
          if (suspendedSharedLockCount != null) _sharedThreads.put(currentThread,suspendedSharedLockCount);           //  PK96860
   
          obtained = false;          
        }
        else
        {
          // No other thread is holding or waiting for the exclusive lock. This thread will obtain it when
          // there are no shared locks (other that this threads) in the system.

          // First, update _threadRequestingExclusiveLock so other threads will know we are
          // requesting the exclusive lock.
          _threadRequestingExclusiveLock = currentThread;

          if (tc.isDebugEnabled()) Tr.debug(tc, "Thread " + Integer.toHexString(currentThread.hashCode()) + " is waiting for the shared locks to quiesce");

          while ( (_sharedThreads.size() > 1) ||
                  ((_sharedThreads.size() == 1) && (!_sharedThreads.containsKey(currentThread))) )
          {
            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.attemptExclusiveLock", "362", 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()) + " has detected that the shared locks have quiesced");

          _threadHoldingExclusiveLock = currentThread;
          _threadRequestingExclusiveLock = null;
          obtained = true;
        }
      }
    }
        
    if (tc.isEntryEnabled()) Tr.exit(tc, "attemptExclusiveLock","" + obtained);

    return obtained;
  }
public boolean attemptExclusiveLock ( ) throws HoldingExclusiveLockException { if ( tc . isEntryEnabled ( ) ) Tr . entry ( tc , "attemptExclusiveLock" , this ) ; boolean obtained = false ; Thread currentThread = Thread . currentThread ( ) ; synchronized ( this ) { if ( ( _threadHoldingExclusiveLock != null ) && ( _threadHoldingExclusiveLock . equals ( currentThread ) ) ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "attemptExclusiveLock" , "HoldingExclusiveLockException" ) ; throw new HoldingExclusiveLockException ( ) ; } else { if ( ( _threadHoldingExclusiveLock != null ) || ( _threadRequestingExclusiveLock != null ) ) { Integer suspendedSharedLockCount = ( Integer ) _sharedThreads . get ( currentThread ) ; _sharedThreads . remove ( currentThread ) ; this . notifyAll ( ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " is waiting for the exclusive lock to be released" ) ; while ( ( _threadHoldingExclusiveLock != null ) || ( _threadRequestingExclusiveLock != null ) ) { 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.attemptExclusiveLock" , "325" , this ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " was interrupted unexpectedly during wait. Retesting condition" ) ; } } if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " has detected that the exclusive lock has been released" ) ; if ( suspendedSharedLockCount != null ) _sharedThreads . put ( currentThread , suspendedSharedLockCount ) ; obtained = false ; } else { _threadRequestingExclusiveLock = currentThread ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " is waiting for the shared locks to quiesce" ) ; while ( ( _sharedThreads . size ( ) > 1 ) || ( ( _sharedThreads . size ( ) == 1 ) && ( ! _sharedThreads . containsKey ( currentThread ) ) ) ) { 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.attemptExclusiveLock" , "362" , this ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " was interrupted unexpectedly during wait. Retesting condition" ) ; } } if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , "Thread " + Integer . toHexString ( currentThread . hashCode ( ) ) + " has detected that the shared locks have quiesced" ) ; _threadHoldingExclusiveLock = currentThread ; _threadRequestingExclusiveLock = null ; obtained = true ; } } } if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "attemptExclusiveLock" , "" + obtained ) ; return obtained ; }
Requests the 'exclusive' lock. Multiple threads may hold shared locks concurrently
but only one thread may hold the 'exclusive' lock at a time.

@exception HoldingExclusiveLockException This thread already holds the exclusive lock.
@return boolean Indicates if the caller has managed to obtain the exclusive lock.