Search in sources :

Example 46 with MonitorInfo

use of java.lang.management.MonitorInfo in project com.revolsys.open by revolsys.

the class DeadlockLogger method toString.

private Object toString(final ThreadInfo threadInfo) {
    final String threadName = threadInfo.getThreadName();
    final long threadId = threadInfo.getThreadId();
    final State threadState = threadInfo.getThreadState();
    final StringBuilder sb = new StringBuilder("\"" + threadName + "\"" + " Id=" + threadId + " " + threadState);
    final String lockName = threadInfo.getLockName();
    if (lockName != null) {
        sb.append(" on " + lockName);
    }
    final String lockOwnerName = threadInfo.getLockOwnerName();
    if (lockOwnerName != null) {
        final long lockOwnerId = threadInfo.getLockOwnerId();
        sb.append(" owned by \"" + lockOwnerName + "\" Id=" + lockOwnerId);
    }
    if (threadInfo.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (threadInfo.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    final StackTraceElement[] stackTrace = threadInfo.getStackTrace();
    int i = 0;
    for (; i < stackTrace.length && i < 500; i++) {
        final StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        final LockInfo lockInfo = threadInfo.getLockInfo();
        if (i == 0 && lockInfo != null) {
            final Thread.State ts = threadState;
            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:
            }
        }
        final MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
        for (final MonitorInfo mi : lockedMonitors) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    if (i < stackTrace.length) {
        sb.append("\t...");
        sb.append('\n');
    }
    final LockInfo[] locks = threadInfo.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = " + locks.length);
        sb.append('\n');
        for (final LockInfo li : locks) {
            sb.append("\t- " + li);
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : State(java.lang.Thread.State) MonitorInfo(java.lang.management.MonitorInfo) State(java.lang.Thread.State) LockInfo(java.lang.management.LockInfo)

Example 47 with MonitorInfo

use of java.lang.management.MonitorInfo in project h2database by h2database.

the class AbbaLockingDetector method generateOrdering.

/**
 * We cannot simply call getLockedMonitors because it is not guaranteed to
 * return the locks in the correct order.
 */
private static void generateOrdering(final List<String> lockOrder, ThreadInfo info) {
    final MonitorInfo[] lockedMonitors = info.getLockedMonitors();
    Arrays.sort(lockedMonitors, new Comparator<MonitorInfo>() {

        @Override
        public int compare(MonitorInfo a, MonitorInfo b) {
            return b.getLockedStackDepth() - a.getLockedStackDepth();
        }
    });
    for (MonitorInfo mi : lockedMonitors) {
        String lockName = getObjectName(mi);
        if (lockName.equals("sun.misc.Launcher$AppClassLoader")) {
            // ignore, it shows up everywhere
            continue;
        }
        // succession - Java locks are recursive.
        if (!lockOrder.contains(lockName)) {
            lockOrder.add(lockName);
        }
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Example 48 with MonitorInfo

use of java.lang.management.MonitorInfo 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 49 with MonitorInfo

use of java.lang.management.MonitorInfo in project indy by Commonjava.

the class ThreadDumper method dumpThreads.

public static void dumpThreads() {
    StringBuilder sb = new StringBuilder();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
    Stream.of(threadInfos).forEachOrdered((ti) -> {
        if (sb.length() > 0) {
            sb.append("\n\n");
        }
        sb.append(ti.getThreadName()).append("\n  State: ").append(ti.getThreadState()).append("\n  Lock Info: ").append(ti.getLockInfo()).append("\n  Monitors:");
        MonitorInfo[] monitors = ti.getLockedMonitors();
        if (monitors == null || monitors.length < 1) {
            sb.append("  -NONE-");
        } else {
            sb.append("\n  - ").append(join(monitors, "\n  - "));
        }
        sb.append("\n  Trace:\n    ").append(join(ti.getStackTrace(), "\n    "));
    });
    System.out.println(sb);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) MonitorInfo(java.lang.management.MonitorInfo)

Example 50 with MonitorInfo

use of java.lang.management.MonitorInfo in project indy by Commonjava.

the class ThreadDumper method dumpThreads.

public static void dumpThreads() {
    StringBuilder sb = new StringBuilder();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
    Stream.of(threadInfos).forEachOrdered((ti) -> {
        if (sb.length() > 0) {
            sb.append("\n\n");
        }
        sb.append(ti.getThreadName()).append("\n  State: ").append(ti.getThreadState()).append("\n  Lock Info: ").append(ti.getLockInfo()).append("\n  Monitors:");
        MonitorInfo[] monitors = ti.getLockedMonitors();
        if (monitors == null || monitors.length < 1) {
            sb.append("  -NONE-");
        } else {
            sb.append("\n  - ").append(join(monitors, "\n  - "));
        }
        sb.append("\n  Trace:\n    ").append(join(ti.getStackTrace(), "\n    "));
    });
    System.out.println(sb);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) MonitorInfo(java.lang.management.MonitorInfo)

Aggregations

MonitorInfo (java.lang.management.MonitorInfo)78 LockInfo (java.lang.management.LockInfo)41 ThreadInfo (java.lang.management.ThreadInfo)18 ThreadMXBean (java.lang.management.ThreadMXBean)10 Test (org.testng.annotations.Test)8 CompositeData (javax.management.openmbean.CompositeData)7 OutputStreamWriter (java.io.OutputStreamWriter)6 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)3 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 State (java.lang.Thread.State)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 OpenDataException (javax.management.openmbean.OpenDataException)2 MonitorInfoMetricSnapshot (com.navercorp.pinpoint.profiler.monitor.metric.deadlock.MonitorInfoMetricSnapshot)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompositeType (javax.management.openmbean.CompositeType)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1