Java.Util.Concurrent.Locks.ReentrantLock.IsHeldByCurrentThread Property
Queries if this lock is held by the current thread.

Syntax

[get: Android.Runtime.Register("isHeldByCurrentThread", "()Z", "GetIsHeldByCurrentThreadHandler")]
public virtual bool IsHeldByCurrentThread { get; }

Value

Documentation for this section has not yet been entered.

Remarks

Queries if this lock is held by the current thread.

Analogous to the Java.Lang.Thread.HoldsLock(Java.Lang.Object) method for built-in monitor locks, this method is typically used for debugging and testing. For example, a method that should only be called while a lock is held can assert that this is the case:

java Example

class X {
   ReentrantLock lock = new ReentrantLock();
   // ...

   public void m() {
       assert lock.isHeldByCurrentThread();
       // ... method body
   
 }}

It can also be used to ensure that a reentrant lock is used in a non-reentrant manner, for example:

java Example

class X {
   ReentrantLock lock = new ReentrantLock();
   // ...

   public void m() {
       assert !lock.isHeldByCurrentThread();
       lock.lock();
       try {
           // ... method body
        finally {
           lock.unlock();
       }
   }
 }}

[Android Documentation]

Requirements

Namespace: Java.Util.Concurrent.Locks
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1