Is there a way to tell, for a Java object, which Thread (or null) currently owns its monitor? Or at least a way to tell if the current thread owns it?
In Java 1.6 you can use Reflection to get this information.
ThreadMXBean tBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threadInfo = tBean .getThreadInfo(bean.getAllThreadIds(), true, true);