Search in sources :

Example 36 with ThreadInfo

use of java.lang.management.ThreadInfo in project jgnash by ccavanaugh.

the class EventDispatchThreadHangMonitor method checkForDeadlock.

private static void checkForDeadlock() {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long[] threadIds = threadBean.findMonitorDeadlockedThreads();
    if (threadIds == null) {
        return;
    }
    Log.warn("deadlock detected involving the following threads:");
    ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
    for (ThreadInfo info : threadInfos) {
        Log.warn("Thread #" + info.getThreadId() + " " + info.getThreadName() + " (" + info.getThreadState() + ") waiting on " + info.getLockName() + " held by " + info.getLockOwnerName() + stackTraceToString(info.getStackTrace()));
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Example 37 with ThreadInfo

use of java.lang.management.ThreadInfo in project cdap by caskdata.

the class ReflectionUtils method printThreadInfo.

/**
   * Print all of the thread's information and stack traces.
   *
   * @param stream the stream to
   * @param title a string title for the stack trace
   */
public static synchronized void printThreadInfo(PrintWriter stream, String title) {
    final int stackDepth = 20;
    boolean contention = threadBean.isThreadContentionMonitoringEnabled();
    long[] threadIds = threadBean.getAllThreadIds();
    stream.println("Process Thread Dump: " + title);
    stream.println(threadIds.length + " active threads");
    for (long tid : threadIds) {
        ThreadInfo info = threadBean.getThreadInfo(tid, stackDepth);
        if (info == null) {
            stream.println("  Inactive");
            continue;
        }
        stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":");
        Thread.State state = info.getThreadState();
        stream.println("  State: " + state);
        stream.println("  Blocked count: " + info.getBlockedCount());
        stream.println("  Waited count: " + info.getWaitedCount());
        if (contention) {
            stream.println("  Blocked time: " + info.getBlockedTime());
            stream.println("  Waited time: " + info.getWaitedTime());
        }
        if (state == Thread.State.WAITING) {
            stream.println("  Waiting on " + info.getLockName());
        } else if (state == Thread.State.BLOCKED) {
            stream.println("  Blocked on " + info.getLockName());
            stream.println("  Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
        }
        stream.println("  Stack:");
        for (StackTraceElement frame : info.getStackTrace()) {
            stream.println("    " + frame.toString());
        }
    }
    stream.flush();
}
Also used : ThreadInfo(java.lang.management.ThreadInfo)

Example 38 with ThreadInfo

use of java.lang.management.ThreadInfo in project jdk8u_jdk by JetBrains.

the class ThreadMonitor method dumpThreadInfoWithLocks.

/**
     * Prints the thread dump information with locks info to System.out.
     */
private void dumpThreadInfoWithLocks() {
    System.out.println("Full Java thread dump with locks info");
    ThreadInfo[] tinfos = tmbean.dumpAllThreads(true, true);
    for (ThreadInfo ti : tinfos) {
        printThreadInfo(ti);
        LockInfo[] syncs = ti.getLockedSynchronizers();
        printLockInfo(syncs);
    }
    System.out.println();
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) LockInfo(java.lang.management.LockInfo)

Example 39 with ThreadInfo

use of java.lang.management.ThreadInfo in project jdk8u_jdk by JetBrains.

the class JvmThreadInstanceTableMetaImpl method getJvmThreadInstance.

private JvmThreadInstanceEntryImpl getJvmThreadInstance(Object userData, SnmpOid oid) {
    JvmThreadInstanceEntryImpl cached = null;
    String entryTag = null;
    Map<Object, Object> map = null;
    final boolean dbg = log.isDebugOn();
    if (userData instanceof Map) {
        map = Util.cast(userData);
        // We're going to use this name to store/retrieve the entry in
        // the request contextual cache.
        //
        // Revisit: Probably better programming to put all these strings
        //          in some interface.
        //
        entryTag = "JvmThreadInstanceTable.entry." + oid.toString();
        cached = (JvmThreadInstanceEntryImpl) map.get(entryTag);
    }
    //
    if (cached != null) {
        if (dbg)
            log.debug("*** getJvmThreadInstance", "Entry found in cache: " + entryTag);
        return cached;
    }
    if (dbg)
        log.debug("*** getJvmThreadInstance", "Entry [" + oid + "] is not in cache");
    // Entry not in cache. We will create one if needed.
    //
    ThreadInfo info = null;
    try {
        info = getThreadInfo(oid);
    } catch (RuntimeException r) {
        log.trace("*** getJvmThreadInstance", "Failed to get thread info for rowOid: " + oid);
        log.debug("*** getJvmThreadInstance", r);
    }
    //
    if (info == null) {
        if (dbg)
            log.debug("*** getJvmThreadInstance", "No entry by that oid [" + oid + "]");
        return null;
    }
    cached = new JvmThreadInstanceEntryImpl(info, oid.toByte());
    if (map != null)
        map.put(entryTag, cached);
    if (dbg)
        log.debug("*** getJvmThreadInstance", "Entry created for Thread OID [" + oid + "]");
    return cached;
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) SnmpString(com.sun.jmx.snmp.SnmpString) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 40 with ThreadInfo

use of java.lang.management.ThreadInfo in project processdash by dtuma.

the class ThreadMonitor method dumpThreadInfo.

/**
     * Prints the thread dump information to System.out.
     */
public void dumpThreadInfo() {
    System.out.println("Full Java thread dump");
    long[] tids = tmbean.getAllThreadIds();
    ThreadInfo[] tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
    for (ThreadInfo ti : tinfos) {
        printThreadInfo(ti);
    }
}
Also used : ThreadInfo(java.lang.management.ThreadInfo)

Aggregations

ThreadInfo (java.lang.management.ThreadInfo)124 ThreadMXBean (java.lang.management.ThreadMXBean)56 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LockInfo (java.lang.management.LockInfo)6 MonitorInfo (java.lang.management.MonitorInfo)6 Test (org.junit.Test)5 Date (java.util.Date)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 FileOutputStream (java.io.FileOutputStream)3 PrintStream (java.io.PrintStream)3 PrintWriter (java.io.PrintWriter)3 Method (java.lang.reflect.Method)3 LinkedHashSet (java.util.LinkedHashSet)3 TreeMap (java.util.TreeMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 HealthCheckResultEntry (fish.payara.notification.healthcheck.HealthCheckResultEntry)2