http://blog.csdn.net/w410589502/article/details/54949506
java.lang.Thread中有一个方法叫holdsLock(),它返回true如果当且仅当当前线程拥有某个具体对象的锁
Object o = new Object(); @Test public void test1() throws Exception { new Thread(new Runnable() { @Override public void run() { synchronized(o) { System.out.println("child thread: holdLock: " + Thread.holdsLock(o)); } } }).start(); System.out.println("main thread: holdLock: " + Thread.holdsLock(o)); Thread.sleep(2000); }
main thread: holdLock: false
child thread: holdLock: true