Java Thread.holdsLock(Object obj)

Syntax

Thread.holdsLock(Object obj) has the following syntax.

public static boolean holdsLock(Object obj)

Example

In the following code shows how to use Thread.holdsLock(Object obj) method.


//w  w  w. j a  v  a  2 s .c o m
class ThreadDemo implements Runnable {

  public void run() {

    System.out.println("Holds Lock = " + Thread.holdsLock(this));

    synchronized (this) {
      System.out.println("Holds Lock = " + Thread.holdsLock(this));
    }
  }
}

public class Main {

  public static void main(String[] args) {

    Thread th = new Thread(new ThreadDemo());
    th.start();
  }

}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable