Search in sources :

Example 36 with LockInfo

use of java.lang.management.LockInfo in project aion by aionnetwork.

the class ThreadDumper method dumpThreadInfo.

public static String dumpThreadInfo() {
    final StringBuilder sb = new StringBuilder();
    final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    for (Thread t : Thread.getAllStackTraces().keySet()) {
        if (t.isAlive()) {
            ThreadInfo threadInfo = threadMXBean.getThreadInfo(t.getId());
            sb.append(threadInfo.toString());
            sb.deleteCharAt(sb.length() - 1);
            for (StackTraceElement ste : t.getStackTrace()) {
                sb.append("\tat ").append(ste.getClassName()).append(".").append(ste.getMethodName()).append("(").append(ste.getFileName()).append(":").append(ste.getLineNumber()).append(")");
                sb.append("\n");
            }
            sb.append("Ownable synchronizers:");
            LockInfo[] s = threadInfo.getLockedSynchronizers();
            if (s == null || s.length == 0) {
                sb.append(" None.\n");
            } else {
                sb.append("\n");
                for (final LockInfo lockInfo : s) {
                    sb.append(lockInfo.getClassName()).append(" <").append(lockInfo.getIdentityHashCode()).append("> \n");
                }
            }
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) LockInfo(java.lang.management.LockInfo)

Example 37 with LockInfo

use of java.lang.management.LockInfo in project knime-core by knime.

the class ThreadUtils method fillStackFromThread.

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

Example 38 with LockInfo

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

the class ThreadDumpService method requestCommandService.

@Override
public TBase<?, ?> requestCommandService(TBase tbase) {
    logger.info("{} execute {}.", this, tbase);
    TCommandThreadDump param = (TCommandThreadDump) tbase;
    TThreadDumpType type = param.getType();
    List<ThreadInfo> threadInfoList = null;
    if (TThreadDumpType.TARGET == type) {
        threadInfoList = getThreadInfo(param.getName());
    } else if (TThreadDumpType.PENDING == type) {
        threadInfoList = getThreadInfo(param.getPendingTimeMillis());
    } else {
        threadInfoList = Arrays.asList(getAllThreadInfo());
    }
    TCommandThreadDumpResponse response = new TCommandThreadDumpResponse();
    for (ThreadInfo info : threadInfoList) {
        TThreadDump dump = new TThreadDump();
        dump.setThreadName(info.getThreadName());
        dump.setThreadId(info.getThreadId());
        dump.setBlockedTime(info.getBlockedTime());
        dump.setBlockedCount(info.getBlockedCount());
        dump.setWaitedTime(info.getWaitedTime());
        dump.setWaitedCount(info.getWaitedCount());
        dump.setLockName(info.getLockName());
        dump.setLockOwnerId(info.getLockOwnerId());
        dump.setLockOwnerName(info.getLockOwnerName());
        dump.setInNative(info.isInNative());
        dump.setSuspended(info.isSuspended());
        dump.setThreadState(getThreadState(info));
        StackTraceElement[] stackTraceElements = info.getStackTrace();
        for (StackTraceElement each : stackTraceElements) {
            dump.addToStackTrace(each.toString());
        }
        MonitorInfo[] monitorInfos = info.getLockedMonitors();
        for (MonitorInfo each : monitorInfos) {
            TMonitorInfo tMonitorInfo = new TMonitorInfo();
            tMonitorInfo.setStackDepth(each.getLockedStackDepth());
            tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString());
            dump.addToLockedMonitors(tMonitorInfo);
        }
        LockInfo[] lockInfos = info.getLockedSynchronizers();
        for (LockInfo lockInfo : lockInfos) {
            dump.addToLockedSynchronizers(lockInfo.toString());
        }
        response.addToThreadDumps(dump);
    }
    return response;
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) ThreadInfo(java.lang.management.ThreadInfo) LockInfo(java.lang.management.LockInfo)

Example 39 with LockInfo

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

the class ThreadDumpUtils method setLockInfo.

private static void setLockInfo(TThreadDump threadDump, ThreadInfo threadInfo) {
    threadDump.setLockName(threadInfo.getLockName());
    threadDump.setLockOwnerId(threadInfo.getLockOwnerId());
    threadDump.setLockOwnerName(threadInfo.getLockOwnerName());
    LockInfo[] lockInfos = threadInfo.getLockedSynchronizers();
    if (lockInfos != null) {
        for (LockInfo lockInfo : lockInfos) {
            if (lockInfo == null) {
                continue;
            }
            threadDump.addToLockedSynchronizers(lockInfo.toString());
        }
    } else {
        threadDump.setLockedSynchronizers(Collections.<String>emptyList());
    }
}
Also used : LockInfo(java.lang.management.LockInfo)

Example 40 with LockInfo

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

the class LocalThread method generateThreadStack.

private String generateThreadStack(ThreadInfo info) {
    // This is annoying, but the to string method on info sucks.
    StringBuilder result = new StringBuilder();
    result.append(info.getThreadName()).append(" ID=0x").append(Long.toHexString(info.getThreadId())).append("(").append(info.getThreadId()).append(") state=").append(info.getThreadState());
    if (info.getLockInfo() != null) {
        result.append("\n\twaiting to lock <" + info.getLockInfo() + ">");
    }
    for (StackTraceElement element : info.getStackTrace()) {
        result.append("\n\tat " + element);
        for (MonitorInfo monitor : info.getLockedMonitors()) {
            if (element.equals(monitor.getLockedStackFrame())) {
                result.append("\n\tlocked <" + monitor + ">");
            }
        }
    }
    if (info.getLockedSynchronizers().length > 0) {
        result.append("\nLocked synchronizers:");
        for (LockInfo sync : info.getLockedSynchronizers()) {
            result.append("\n" + sync.getClassName() + "@" + Integer.toHexString(sync.getIdentityHashCode()));
        }
    }
    return result.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) 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