if (monitorName.equalsIgnoreCase("")) {
monitorName = "<un-named monitor>";
}
out.println("id: 0x" + jMonitor.getID() + " name: " + jMonitor.getName());
JavaThread owner = jMonitor.getOwner();
if (null != owner) {
try {
out.println("\towner thread id: " + owner.getImageThread().getID()
+ " name: " + owner.getName());
} catch (DataUnavailable e) {
out.println("\towner thread id: " + Exceptions.getDataUnavailableString());
}
}
// List any threads waiting on enter or notify for this monitor
Iterator itEnterWaiter = jMonitor.getEnterWaiters().iterator();
while (itEnterWaiter.hasNext()) {
JavaThread jThread = (JavaThread)itEnterWaiter.next();
try {
out.println("\twaiting thread id: " + jThread.getImageThread().getID()
+ " name: " + jThread.getName());
} catch (DataUnavailable dae) {
out.println("\twaiting thread id: <unknown>");
}
}
Iterator itNotifyWaiter = jMonitor.getNotifyWaiters().iterator();
while (itNotifyWaiter.hasNext()) {
JavaThread jThread = (JavaThread)itNotifyWaiter.next();
try {
out.println("\twaiting thread id: " + jThread.getImageThread().getID()
+ " name: " + jThread.getName());
} catch (DataUnavailable dae) {
out.println("\twaiting thread id: <unknown>");
}
}
} catch(CorruptDataException cde) {
out.println("\nwarning, corrupt data encountered during scan for system locks...");
}
if (null != jObject) {
// Remember object monitors (flat or inflated) for later
vMonitorsWithLockedObjects.add(jMonitor);
}
}
}
out.println("\nLocked objects...");
if (0 == vMonitorsWithLockedObjects.size()){
out.println("\t...None.");
return;
}
Iterator lockedObjects = vMonitorsWithLockedObjects.iterator();
while(lockedObjects.hasNext()){
JavaMonitor jMonitor = (JavaMonitor)lockedObjects.next();
JavaObject jObject = jMonitor.getObject();
try{
JavaThread owner = jMonitor.getOwner();
String className = "<unknown class>";
JavaClass jClass = jObject.getJavaClass();
if (null != jClass) {
className = jClass.getName();
}
String jObjectID = Long.toHexString(jObject.getID().getAddress());
if (null == owner) {
out.println(className + "@0x" + jObjectID + " locked by an unknown thread");
} else {
String owningThreadID = null;
try {
owningThreadID = owner.getImageThread().getID();
} catch (DataUnavailable e) {
owningThreadID = Exceptions.getDataUnavailableString();
}
out.println(className + "@0x" + jObjectID + "\n\tlocked by thread id: "
+ owningThreadID + " name: " + owner.getName());
}
}catch(CorruptDataException cde){
}
}
}