Top Description Methods
com.jogamp.common.util.locks

public Interface RecursiveThreadGroupLock

extends RecursiveLock
Known Direct Implementers
jogamp.common.util.locks.RecursiveThreadGroupLockImpl01Unfairish

Reentrance capable locking toolkit, supporting multiple threads as owner.

See use case description at addOwner(Thread).

Method Summary

Modifier and TypeMethod and Description
public void
addOwner(Thread
the thread to be added to the list of additional owning threads
t
)

Add a thread to the list of additional lock owners, which enables them to recursively claim this lock.

public boolean
isOriginalOwner()

Returns true if the current thread is the original lock owner, ie.

public boolean
isOriginalOwner(Thread thread)

Returns true if the passed thread is the original lock owner, ie.

public void
removeOwner(Thread
the thread to be removed from the list of additional owning threads
t
)

Remove a thread from the list of additional lock owner threads.

public void
unlock()

Redeclares com.jogamp.common.util.locks.Lock.unlock.

Wait's until all additional owners released this lock before releasing it.

public void
unlock(Runnable taskAfterUnlockBeforeNotify)

Redeclares com.jogamp.common.util.locks.ThreadLock.unlock.

Wait's until all additional owners released this lock before releasing it.

Inherited from com.jogamp.common.util.locks.RecursiveLock:
getHoldCountgetQueueLength

Method Detail

addOwnerback to summary
public void addOwner(Thread t) throws RuntimeException, IllegalArgumentException

Add a thread to the list of additional lock owners, which enables them to recursively claim this lock.

The caller must hold this lock and be the original lock owner, see isOriginalOwner().

If the original owner releases this lock via unlock() all additional lock owners are released as well. This ensures consistency of spawn off additional lock owner threads and it's release.

Use case:
Thread2 thread2 = new Thread2();

Thread1 {

  // Claim this lock and become the original lock owner.
  lock.lock();

  try {

    // Allow Thread2 to claim the lock, ie. make thread2 an additional lock owner
    addOwner(thread2);

    // Start thread2
    thread2.start();

    // Wait until thread2 has finished requiring this lock, but keep thread2 running
    while(!thread2.waitForResult()) sleep();

    // Optional: Only if sure that this thread doesn't hold the lock anymore,
    // otherwise just release the lock via unlock().
    removeOwner(thread2);

  } finally {

    // Release this lock and remove all additional lock owners.
    // Implicit wait until thread2 gets off the lock.
    lock.unlock();

  }

}.start();
Parameters
t:Thread

the thread to be added to the list of additional owning threads

Exceptions
RuntimeException:
if the current thread does not hold the lock.
IllegalArgumentException:
if the passed thread is the lock owner or already added.
See Also
removeOwner(Thread), unlock(), lock()
isOriginalOwnerback to summary
public boolean isOriginalOwner()

Returns true if the current thread is the original lock owner, ie. successfully claimed this lock the first time, ie. getHoldCount() == 1.

isOriginalOwnerback to summary
public boolean isOriginalOwner(Thread thread)

Returns true if the passed thread is the original lock owner, ie. successfully claimed this lock the first time, ie. getHoldCount() == 1.

removeOwnerback to summary
public void removeOwner(Thread t) throws RuntimeException, IllegalArgumentException

Remove a thread from the list of additional lock owner threads.

The caller must hold this lock and be the original lock owner, see isOriginalOwner().

Only use this method if sure that the thread doesn't hold the lock anymore.

Parameters
t:Thread

the thread to be removed from the list of additional owning threads

Exceptions
RuntimeException:
if the current thread does not hold the lock.
IllegalArgumentException:
if the passed thread is not added by addOwner(Thread)
unlockback to summary
public void unlock() throws RuntimeException

Redeclares com.jogamp.common.util.locks.Lock.unlock.

Doc from com.jogamp.common.util.locks.Lock.unlock.

Wait's until all additional owners released this lock before releasing it.

Release the lock.
Annotations
@Override
Exceptions
RuntimeException:
in case the lock is not acquired by this thread.
unlockback to summary
public void unlock(Runnable taskAfterUnlockBeforeNotify)

Redeclares com.jogamp.common.util.locks.ThreadLock.unlock.

Doc from com.jogamp.common.util.locks.ThreadLock.unlock.

Wait's until all additional owners released this lock before releasing it.

Execute the Runnable taskAfterUnlockBeforeNotify while holding the exclusive lock.

Then release the lock.

Annotations
@Override