## org.exist.storage.lock
Class ReentrantReadWriteLock

    java.lang.Object
      org.exist.storage.lock.ReentrantReadWriteLock

All Implemented Interfaces:
  Lock

public class ReentrantReadWriteLock
extends java.lang.Object
implements Lock

A lock with the same semantics as builtin Java synchronized locks: Once a thread has a lock, it can re-obtain it any number of times without blocking. The lock is made available to other threads when as many releases as acquires have occurred. The lock has a timeout: a read lock will be released if the timeout is reached.

Field Summary

Fields inherited from interface org.exist.storage.lock.Lock
`NO_LOCK, READ_LOCK, WRITE_LOCK`

Constructor Summary
`ReentrantReadWriteLock(java.lang.String id)`

Method Summary
`boolean` `acquire()` Acquire a lock for read.
`boolean` `acquire(int mode)` Acquire a lock for read or write.
`boolean` `attempt(int mode)` Attempt to acquire a lock for read or write.
`long` `holds()` Return the number of unreleased acquires performed by the current thread.
`boolean` `isLockedForWrite()` Returns true if there are active or pending write locks.
`void` `release()` Release the lock.
`void` `release(int mode)` Release a lock of the specified type.
`void` `release(long n)` Release the lock N times.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ReentrantReadWriteLock

    public ReentrantReadWriteLock(java.lang.String id)

Method Detail

### acquire

    public boolean acquire()
                    throws LockException

  Description copied from interface: `Lock`
  Acquire a lock for read.

  Specified by:
    `acquire` in interface `Lock`
  Throws:
    `LockException`

### acquire

    public boolean acquire(int mode)
                    throws LockException

  Description copied from interface: `Lock`
  Acquire a lock for read or write. mode is one of `Lock.READ_LOCK` or `Lock.WRITE_LOCK`.

  Specified by:
    `acquire` in interface `Lock`
  Parameters:
    `mode` -
  Throws:
    `LockException`

### attempt

    public boolean attempt(int mode)

  Description copied from interface: `Lock`
  Attempt to acquire a lock for read or write. This method will fail immediately if the lock cannot be acquired.

  Specified by:
    `attempt` in interface `Lock`
  Parameters:
    `mode` -

### isLockedForWrite

    public boolean isLockedForWrite()

  Description copied from interface: `Lock`
  Returns true if there are active or pending write locks.

  Specified by:
    `isLockedForWrite` in interface `Lock`

### release

    public void release(int mode)

  Description copied from interface: `Lock`
  Release a lock of the specified type.

  Specified by:
    `release` in interface `Lock`
  Parameters:
    `mode` -

### release

    public void release()

  Release the lock.

  Specified by:
    `release` in interface `Lock`
  Throws:
    `java.lang.Error` - thrown if not current owner of lock

### release

    public void release(long n)

  Release the lock N times. `release(n)` is equivalent in effect to:

         for (int i = 0; i < n; ++i) release();

  Throws:
    `java.lang.Error` - thrown if not current owner of lock or has fewer than N holds on the lock

### holds

    public long holds()

  Return the number of unreleased acquires performed by the current thread. Returns zero if current thread does not hold lock.

Copyright (C) Wolfgang Meier. All rights reserved.