Search in sources :

Example 26 with LockInfo

use of java.lang.management.LockInfo in project activemq-artemis by apache.

the class ThreadDumpUtil method threadInfoToString.

private static String threadInfoToString(ThreadInfo threadInfo) {
    StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState());
    if (threadInfo.getLockName() != null) {
        sb.append(" on " + threadInfo.getLockName());
    }
    if (threadInfo.getLockOwnerName() != null) {
        sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId());
    }
    if (threadInfo.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (threadInfo.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    int i = 0;
    for (; i < threadInfo.getStackTrace().length; i++) {
        StackTraceElement ste = threadInfo.getStackTrace()[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && threadInfo.getLockInfo() != null) {
            Thread.State ts = threadInfo.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : threadInfo.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    LockInfo[] locks = threadInfo.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 27 with LockInfo

use of java.lang.management.LockInfo in project tomcat70 by apache.

the class Diagnostics method getThreadDump.

/**
 * Formats the thread dump for one thread.
 *
 * @param ti the ThreadInfo describing the thread
 * @return the formatted thread dump
 */
private static String getThreadDump(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder(getThreadDumpHeader(ti));
    for (LockInfo li : ti.getLockedSynchronizers()) {
        sb.append(INDENT2 + "locks " + li.toString() + CRLF);
    }
    boolean start = true;
    StackTraceElement[] stes = ti.getStackTrace();
    Object[] monitorDepths = new Object[stes.length];
    MonitorInfo[] mis = ti.getLockedMonitors();
    for (int i = 0; i < mis.length; i++) {
        monitorDepths[mis[i].getLockedStackDepth()] = mis[i];
    }
    for (int i = 0; i < stes.length; i++) {
        StackTraceElement ste = stes[i];
        sb.append(INDENT2 + "at " + ste.toString() + CRLF);
        if (start) {
            if (ti.getLockName() != null) {
                sb.append(INDENT2 + "- waiting on (a " + ti.getLockName() + ")");
                if (ti.getLockOwnerName() != null) {
                    sb.append(" owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId());
                }
                sb.append(CRLF);
            }
            start = false;
        }
        if (monitorDepths[i] != null) {
            MonitorInfo mi = (MonitorInfo) monitorDepths[i];
            sb.append(INDENT2 + "- locked (a " + mi.toString() + ")" + " index " + mi.getLockedStackDepth() + " frame " + mi.getLockedStackFrame().toString());
            sb.append(CRLF);
        }
    }
    return sb.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 28 with LockInfo

use of java.lang.management.LockInfo in project kafka by apache.

the class SynchronizationTest method threadInfoToString.

private static String threadInfoToString(ThreadInfo info) {
    StringBuilder sb = new StringBuilder("\"" + info.getThreadName() + "\"" + " Id=" + info.getThreadId() + " " + info.getThreadState());
    if (info.getLockName() != null) {
        sb.append(" on " + info.getLockName());
    }
    if (info.getLockOwnerName() != null) {
        sb.append(" owned by \"" + info.getLockOwnerName() + "\" Id=" + info.getLockOwnerId());
    }
    if (info.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (info.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    // this has been refactored for checkstyle
    printStacktrace(info, sb);
    LockInfo[] locks = info.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 : LockInfo(java.lang.management.LockInfo)

Example 29 with LockInfo

use of java.lang.management.LockInfo in project pinpoint by naver.

the class DeadlockMonitorTask method createThreadDump.

/**
 * refer to java.lang.management.ThreadInfo.toString {@link ThreadInfo}
 * To find loadClass cause. MAX_FRAME is too short , the length.
 */
private String createThreadDump(ThreadInfo threadInfo) {
    StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState());
    if (threadInfo.getLockName() != null) {
        sb.append(" on " + threadInfo.getLockName());
    }
    if (threadInfo.getLockOwnerName() != null) {
        sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId());
    }
    if (threadInfo.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (threadInfo.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    StackTraceElement[] stackTrace = threadInfo.getStackTrace();
    for (int i = 0; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && threadInfo.getLockInfo() != null) {
            LockInfo lockInfo = threadInfo.getLockInfo();
            Thread.State ts = threadInfo.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + lockInfo);
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + lockInfo);
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + lockInfo);
                    sb.append('\n');
                    break;
                default:
            }
        }
        MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
        for (MonitorInfo mi : lockedMonitors) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    LockInfo[] locks = threadInfo.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 30 with LockInfo

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

the class PlainTextThreadDumpFormatter method writeLockedOwnableSynchronizers.

private void writeLockedOwnableSynchronizers(PrintWriter writer, ThreadInfo info) {
    writer.println("   Locked ownable synchronizers:");
    LockInfo[] lockedSynchronizers = info.getLockedSynchronizers();
    if (lockedSynchronizers == null || lockedSynchronizers.length == 0) {
        writer.println("\t- None");
    } else {
        for (LockInfo lockedSynchronizer : lockedSynchronizers) {
            writer.printf("\t- Locked %s%n", format(lockedSynchronizer));
        }
    }
}
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