Determining If the Current Thread Is Holding a Synchronized Lock
public class Main { public static void main(String[] argv) throws Exception { Object o = new Object(); System.out.println(Thread.holdsLock(o)); synchronized (o) { System.out.println(Thread.holdsLock(o)); } } }