JDK-5081501 : Need API to find out which thread has a specific monitor locked
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-08-02
  • Updated: 2006-09-19
  • Resolved: 2006-09-19
Related Reports
Duplicate :  
Description
Name: rmT116609			Date: 08/02/2004


A DESCRIPTION OF THE REQUEST :
The current API allows one to check if the current Thread holds a specific lock (Thread.holdsLock()) but what is needed is a programmatic way to determine: "if this object is locked, who holds it's lock?"

If the object is not locked, return null, otherwise return the Thread holding the lock.

JUSTIFICATION :
Currently there is no way to programmatically retrieve this kind of deadlock information on a remote/head-less JVM.
(Incident Review ID: 290569) 
======================================================================

Comments
EVALUATION JDK 6 enhances the java.lang.management.ThreadMXBean API to obtain the list of locks owned by a given thread to help diagnosing deadlocks (see 6215270). getThreadInfo(long[] ids, boolean lockedMonitors, boolean lockedSynchronizers) returns a snapshot of ThreadInfo for each requested thread. dumpAllThreads(boolean lockedMonitors, boolean lockedSynchronizers) returns ThreadInfo objects for all live threads. findDeadlockedThreads() and findMonitorDeadlockedThreads() returns an array of the thread ID of the deadlocked threads if any. The java.lang.management API can be used locally like an ordinary Java interface as well as remotely using the JMX technology. FYI. The Java Debugger Interface (JDI) provides the API to query what thread is holding an object. (See http://java.sun.com/javase/6/docs/jdk/api/jpda/jdi/com/sun/jdi/ObjectReference.html). To programmatically find deadlocks, the java.lang.management API should satisfy the requirement. So close this CR as a dup of 6215270.
19-09-2006

EVALUATION This might be a candidate for a management interface, if one doesn't already exist.
08-09-2005