Package: org.codehaus.groovy.util

## [Java] Class LockableObject

- org.codehaus.groovy.util.LockableObject

-     public class LockableObject
      extends AbstractQueuedSynchronizer

  A bit simplified lock designed to be inherited by.

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected final boolean` | `isHeldExclusively()` Returns `true` if synchronization is held exclusively with respect to the current (calling) thread. This method is invoked upon each call to a ConditionObject method. The default implementation throws UnsupportedOperationException. This method is invoked internally only within ConditionObject methods, so need not be defined if conditions are not used. throws: UnsupportedOperationException if conditions are not supported Returns: `true` if synchronization is held exclusively; `false` otherwise
    `` | `public final void` | `lock()` Acquires the lock, blocking until it becomes available.
    `` | `protected final boolean` | `tryAcquire(int acquires)` Attempts to acquire in exclusive mode. This method should query if the state of the object permits it to be acquired in the exclusive mode, and if so to acquire it. This method is always invoked by the thread performing acquire. If this method reports failure, the acquire method may queue the thread, if it is not already queued, until it is signalled by a release from some other thread. This can be used to implement method Lock#tryLock()#tryLock(). The default implementation throws UnsupportedOperationException. throws: IllegalMonitorStateException if acquiring would place this synchronizer in an illegal state. This exception must be thrown in a consistent fashion for synchronization to work correctly. throws: UnsupportedOperationException if exclusive mode is not supported Parameters: `arg` - the acquire argument. This value is always the one passed to an acquire method, or is the value saved on entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like. Returns: `true` if successful. Upon success, this object has been acquired.
    `` | `protected final boolean` | `tryRelease(int releases)` Attempts to set the state to reflect a release in exclusive mode. This method is always invoked by the thread performing release. The default implementation throws UnsupportedOperationException. throws: IllegalMonitorStateException if releasing would place this synchronizer in an illegal state. This exception must be thrown in a consistent fashion for synchronization to work correctly. throws: UnsupportedOperationException if exclusive mode is not supported Parameters: `arg` - the release argument. This value is always the one passed to a release method, or the current state value upon entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like. Returns: `true` if this object is now in a fully released state, so that any waiting threads may attempt to acquire; and `false` otherwise.
    `` | `public final void` | `unlock()` Releases one hold of the lock.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class AbstractQueuedSynchronizer` | `acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, equals, getClass, getExclusiveQueuedThreads, getFirstQueuedThread, getQueueLength, getQueuedThreads, getSharedQueuedThreads, getWaitQueueLength, getWaitingThreads, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, hashCode, isQueued, notify, notifyAll, owns, release, releaseShared, toString, tryAcquireNanos, tryAcquireSharedNanos, wait, wait, wait`

- - ### Method Detail

    - #### protected final boolean isHeldExclusively()

      Returns `true` if synchronization is held exclusively with respect to the current (calling) thread. This method is invoked upon each call to a ConditionObject method.

      The default implementation throws UnsupportedOperationException. This method is invoked internally only within ConditionObject methods, so need not be defined if conditions are not used.

      throws:
        UnsupportedOperationException if conditions are not supported
      Returns:
        `true` if synchronization is held exclusively; `false` otherwise

    - #### public final void lock()

      Acquires the lock, blocking until it becomes available.

    - #### protected final boolean tryAcquire(int acquires)

      Attempts to acquire in exclusive mode. This method should query if the state of the object permits it to be acquired in the exclusive mode, and if so to acquire it.

      This method is always invoked by the thread performing acquire. If this method reports failure, the acquire method may queue the thread, if it is not already queued, until it is signalled by a release from some other thread. This can be used to implement method Lock#tryLock()#tryLock().

      The default implementation throws UnsupportedOperationException.

      throws:
        IllegalMonitorStateException if acquiring would place this synchronizer in an illegal state. This exception must be thrown in a consistent fashion for synchronization to work correctly.
      throws:
        UnsupportedOperationException if exclusive mode is not supported
      Parameters:
        `arg` - the acquire argument. This value is always the one passed to an acquire method, or is the value saved on entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
      Returns:
        `true` if successful. Upon success, this object has been acquired.

    - #### protected final boolean tryRelease(int releases)

      Attempts to set the state to reflect a release in exclusive mode.

      This method is always invoked by the thread performing release.

      The default implementation throws UnsupportedOperationException.

      throws:
        IllegalMonitorStateException if releasing would place this synchronizer in an illegal state. This exception must be thrown in a consistent fashion for synchronization to work correctly.
      throws:
        UnsupportedOperationException if exclusive mode is not supported
      Parameters:
        `arg` - the release argument. This value is always the one passed to a release method, or the current state value upon entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
      Returns:
        `true` if this object is now in a fully released state, so that any waiting threads may attempt to acquire; and `false` otherwise.

    - #### public final void unlock()

      Releases one hold of the lock.