Search in sources :

Example 46 with LockInfo

use of java.lang.management.LockInfo in project hudson-2.x by hudson.

the class Functions method dumpThreadInfo.

// ThreadInfo.toString() truncates the stack trace by first 8, so needed my own version
@IgnoreJRERequirement
public static String dumpThreadInfo(ThreadInfo ti, ThreadGroupMap map) {
    String grp = map.getThreadGroup(ti);
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " Group=" + (grp != null ? grp : "?") + " " + ti.getThreadState());
    if (ti.getLockName() != null) {
        sb.append(" on " + ti.getLockName());
    }
    if (ti.getLockOwnerName() != null) {
        sb.append(" owned by \"" + ti.getLockOwnerName() + "\" Id=" + ti.getLockOwnerId());
    }
    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    StackTraceElement[] stackTrace = ti.getStackTrace();
    for (int i = 0; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && ti.getLockInfo() != null) {
            Thread.State ts = ti.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + ti.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + ti.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + ti.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : ti.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    LockInfo[] locks = ti.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = " + locks.length);
        sb.append('\n');
        for (LockInfo li : locks) {
            sb.append("\t- " + li);
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo) IgnoreJRERequirement(org.jvnet.animal_sniffer.IgnoreJRERequirement)

Example 47 with LockInfo

use of java.lang.management.LockInfo in project spring-boot by spring-projects.

the class PlainTextThreadDumpFormatter method writeStackTraceElement.

private void writeStackTraceElement(PrintWriter writer, StackTraceElement element, ThreadInfo info, List<MonitorInfo> lockedMonitors, boolean firstElement) {
    writer.printf("\tat %s%n", element.toString());
    LockInfo lockInfo = info.getLockInfo();
    if (firstElement && lockInfo != null) {
        if (element.getClassName().equals(Object.class.getName()) && element.getMethodName().equals("wait")) {
            writer.printf("\t- waiting on %s%n", format(lockInfo));
        } else {
            String lockOwner = info.getLockOwnerName();
            if (lockOwner != null) {
                writer.printf("\t- waiting to lock %s owned by \"%s\" t@%d%n", format(lockInfo), lockOwner, info.getLockOwnerId());
            } else {
                writer.printf("\t- parking to wait for %s%n", format(lockInfo));
            }
        }
    }
    writeMonitors(writer, lockedMonitors);
}
Also used : LockInfo(java.lang.management.LockInfo)

Example 48 with LockInfo

use of java.lang.management.LockInfo in project angel by Tencent.

the class ThreadUtils method toString.

public static String toString(ThreadInfo tInfo) {
    StringBuilder sb = new StringBuilder("\"" + tInfo.getThreadName() + "\"" + " Id=" + tInfo.getThreadId() + " " + tInfo.getThreadState());
    if (tInfo.getLockName() != null) {
        sb.append(" on " + tInfo.getLockName());
    }
    if (tInfo.getLockOwnerName() != null) {
        sb.append(" owned by \"" + tInfo.getLockOwnerName() + "\" Id=" + tInfo.getLockOwnerId());
    }
    if (tInfo.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (tInfo.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    int i = 0;
    StackTraceElement[] stackTrace = tInfo.getStackTrace();
    for (; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && tInfo.getLockInfo() != null) {
            Thread.State ts = tInfo.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + tInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + tInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + tInfo.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        MonitorInfo[] lockedMonitors = tInfo.getLockedMonitors();
        for (MonitorInfo mi : lockedMonitors) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    LockInfo[] locks = tInfo.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = " + locks.length);
        sb.append('\n');
        for (LockInfo li : locks) {
            sb.append("\t- " + li);
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 49 with LockInfo

use of java.lang.management.LockInfo in project scheduling by ow2-proactive.

the class TimedOutTestsListener method printLockInfo.

private static void printLockInfo(LockInfo[] locks, StringBuilder sb) {
    sb.append(INDENT);
    sb.append("Locked synchronizers: count = ");
    sb.append(locks.length);
    sb.append(System.getProperty("line.separator"));
    for (LockInfo li : locks) {
        sb.append(INDENT);
        sb.append("  - ");
        sb.append(li);
        sb.append(System.getProperty("line.separator"));
    }
    sb.append(System.getProperty("line.separator"));
}
Also used : LockInfo(java.lang.management.LockInfo)

Example 50 with LockInfo

use of java.lang.management.LockInfo in project incubator-pulsar by apache.

the class ThreadDumpUtil method printLockInfo.

private static void printLockInfo(LockInfo[] locks, PrintWriter out) {
    out.println(INDENT + "Locked synchronizers: count = " + locks.length);
    for (LockInfo li : locks) {
        out.println(INDENT + "  - " + li);
    }
    out.println();
}
Also used : LockInfo(java.lang.management.LockInfo)

Aggregations

LockInfo (java.lang.management.LockInfo)69 MonitorInfo (java.lang.management.MonitorInfo)41 ThreadInfo (java.lang.management.ThreadInfo)17 ThreadMXBean (java.lang.management.ThreadMXBean)9 OutputStreamWriter (java.io.OutputStreamWriter)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)4 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 CompositeData (javax.management.openmbean.CompositeData)3 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)2 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 State (java.lang.Thread.State)2 HashSet (java.util.HashSet)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 OpenDataException (javax.management.openmbean.OpenDataException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1