core/src/main/java/com/orientechnologies/common/concur/lock/ScalableRWLock.java
public boolean exclusiveTryLock() {
    // Try to acquire the lock in write-mode
    if (stampedLock.tryWriteLock() == 0) {
      return false;
    }

    // We can only do this after writerOwner has been set to the current thread
    AtomicInteger[] localReadersStateArray = readersStateArrayRef.get();
    if (localReadersStateArray == null) {
      // Set to dummyArray before scanning the readersStateList to impose
      // a linearizability condition
      readersStateArrayRef.set(dummyArray);
      // Copy readersStateList to an array
      localReadersStateArray = readersStateList.toArray(new AtomicInteger[readersStateList.size()]);
      readersStateArrayRef.compareAndSet(dummyArray, localReadersStateArray);
    }

    // Scan the array of Reader states
    for (AtomicInteger readerState : localReadersStateArray) {
      if (readerState != null && readerState.get() == SRWL_STATE_READING) {
        // There is at least one ongoing Reader so give up
        stampedLock.asWriteLock().unlock();
        return false;
      }
    }

    return true;
  }
public boolean exclusiveTryLock() {
    // Try to acquire the lock in write-mode
    if (stampedLock.tryWriteLock() == 0) {
      return false;
    }

    // We can only do this after writerOwner has been set to the current thread
    AtomicInteger[] localReadersStateArray = readersStateArrayRef.get();
    if (localReadersStateArray == null) {
      // Set to dummyArray before scanning the readersStateList to impose
      // a linearizability condition
      readersStateArrayRef.set(dummyArray);
      // Copy readersStateList to an array
      localReadersStateArray = readersStateList.toArray(new AtomicInteger[readersStateList.size()]);
      readersStateArrayRef.compareAndSet(dummyArray, localReadersStateArray);
    }

    // Scan the array of Reader states
    for (AtomicInteger readerState : localReadersStateArray) {
      if (readerState != null && readerState.get() == SRWL_STATE_READING) {
        // There is at least one ongoing Reader so give up
        stampedLock.asWriteLock().unlock();
        return false;
      }
    }

    return true;
  }
public boolean exclusiveTryLock ( ) { // Try to acquire the lock in write-mode if ( stampedLock . tryWriteLock ( ) == 0 ) { return false ; } // We can only do this after writerOwner has been set to the current thread AtomicInteger [ ] localReadersStateArray = readersStateArrayRef . get ( ) ; if ( localReadersStateArray == null ) { // Set to dummyArray before scanning the readersStateList to impose // a linearizability condition readersStateArrayRef . set ( dummyArray ) ; // Copy readersStateList to an array localReadersStateArray = readersStateList . toArray ( new AtomicInteger [ readersStateList . size ( ) ] ) ; readersStateArrayRef . compareAndSet ( dummyArray , localReadersStateArray ) ; } // Scan the array of Reader states for ( AtomicInteger readerState : localReadersStateArray ) { if ( readerState != null && readerState . get ( ) == SRWL_STATE_READING ) { // There is at least one ongoing Reader so give up stampedLock . asWriteLock ( ) . unlock ( ) ; return false ; } } return true ; }
Acquires the write lock only if it is not held by another thread
at the time of invocation.
<p>Acquires the write lock if the write lock is not
held by another thread and returns immediately with
the value {@code true} if and only if no other thread is attempting a
read lock, setting the write lock {@code writerLoop}
count to one.
<p> If the current thread already holds this lock then the
{@code reentrantWriterCount} count is incremented by one and the method returns
{@code true}.
<p>If the write lock is held by another thread then this method
will return immediately with the value {@code false}.

@return {@code true} if the write lock was free and was acquired
by the current thread, or the write lock was already held
by the current thread; and {@code false} otherwise.
Acquires the write lock only if it is not held by another thread at the time of invocation . <p > Acquires the write lock if the write lock is not held by another thread and returns immediately with the value { @code true } if and only if no other thread is attempting a read lock setting the write lock { @code writerLoop } count to one . <p > If the current thread already holds this lock then the { @code reentrantWriterCount } count is incremented by one and the method returns { @code true } . <p > If the write lock is held by another thread then this method will return immediately with the value { @code false } .