public class Main { public static void main(String[] argv) throws Exception { } public synchronized void myMethod() { Object o = new Object(); System.out.println(Thread.holdsLock(o)); synchronized (o) { System.out.println(Thread.holdsLock(o)); } System.out.println(Thread.holdsLock(this)); } }