Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## oracle.ifs.utils.common
Class Mutex

    java.lang.Object
      oracle.ifs.utils.common.Mutex

    public final class Mutex

extends java.lang.Object

This class implements a mutual exclusion lock (mutex). Threads will block trying to acquire the lock if the lock is already owned by another thread. The same thread can acquire the lock multiple times but then it needs to release it the same number of times by calling `Mutex.releaseLock()` or call `Mutex.releaseAllLocks()` before the mutex can be acquired by a different thread.

The owner thread must explicitly release the lock before the thread is disposed of, otherwise it will leave a locked mutex behind.

Constructor Summary
`Mutex()`

Method Summary
`boolean` | `acquireLock()` Waits indefintely to acquire the lock and it is equivalent to calling `acquireLock(0)`.
`boolean` | `acquireLock(long timeout)` Acquires a lock on this mutex.
`int` | `getLockCount()` Returns the number of locks the calling thread has on this mutex.
`boolean` | `isLockedByCurrentThread()` Returns `true` if the current calling thread has at least one lock on this mutex.
`void` | `releaseAllLocks()` Releases all locks that the calling thread holds on this mutex.
`int` | `releaseLock()` Releases one lock on this mutex.

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

Constructor Detail

### Mutex

    public Mutex()

Method Detail

### acquireLock

    public final boolean acquireLock()

  Description copied from class: `Mutex`
  Waits indefintely to acquire the lock and it is equivalent to calling `acquireLock(0)`.

  See Also:
    `Mutex.acquireLock(long)`

### acquireLock

    public final boolean acquireLock(long timeout)

  Description copied from class: `Mutex`
  Acquires a lock on this mutex. A thread that already has the lock may call this method multiple times and the call will return right away but a count of how many locks were acquired is kept. The owner thread must release the lock an equal number of times by calling `Mutex.releaseLock()` or by calling `Mutex.releaseAllLocks()` once.

  Parameters:
    `timeout` - The time in milliseconds to wait to obtain the lock. If the timeout is 0, the thread will wait indefinitely to obtain the lock.
  Returns:
    `true` if the lock was successfully acquired or `false` if the lock could not be acquired.

### releaseLock

    public final int releaseLock()

  Description copied from class: `Mutex`
  Releases one lock on this mutex. If a different thread other than the lock owner threaed tries to release the lock a `RuntimeException` is thrown. The counter will be decremented by one. If the counter reaches zero, the mutex will be completely unlocked and other threads waiting on this mutex will be able to proceed.

  Returns how many locks the calling thread still has left on this mutex, the same as calling `Mutex.getLockCount()`

### releaseAllLocks

    public final void releaseAllLocks()

  Description copied from class: `Mutex`
  Releases all locks that the calling thread holds on this mutex. The mutex will be completely unlocked and other threads waiting on this mutex will be able to proceed.

### isLockedByCurrentThread

    public final boolean isLockedByCurrentThread()

  Description copied from class: `Mutex`
  Returns `true` if the current calling thread has at least one lock on this mutex. If a different thread other than the lock owner threaed tries to release the lock a `RuntimeException` is thrown.

### getLockCount

    public final int getLockCount()

  Description copied from class: `Mutex`
  Returns the number of locks the calling thread has on this mutex.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD