Java Code Examples for java.lang.management.ThreadInfo#getLockedSynchronizers()
The following examples show how to use
java.lang.management.ThreadInfo#getLockedSynchronizers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadDumpUtils.java From pinpoint with Apache License 2.0 | 6 votes |
private static void setLockInfo(ThreadDumpMetricSnapshot 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.addLockedSynchronizer(lockInfo.toString()); } } else { threadDump.setLockedSynchronizers(Collections.<String>emptyList()); } }
Example 2
Source File: CF6Impl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public LI[] getLockedSynchronizers(ThreadInfo info) { LockInfo[] monitors = info.getLockedSynchronizers(); if(monitors == null) { return null; } LI[] results = new LI[monitors.length]; for(int i = 0; i < monitors.length; i++) { results[i] = new LI(monitors[i].getClassName(), monitors[i].getIdentityHashCode()); } return results; }
Example 3
Source File: ThreadMonitor.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example 4
Source File: ThreadMonitor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example 5
Source File: ThreadMonitor.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example 6
Source File: CF6Impl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public LI[] getLockedSynchronizers(ThreadInfo info) { LockInfo[] monitors = info.getLockedSynchronizers(); if(monitors == null) { return null; } LI[] results = new LI[monitors.length]; for(int i = 0; i < monitors.length; i++) { results[i] = new LI(monitors[i].getClassName(), monitors[i].getIdentityHashCode()); } return results; }
Example 7
Source File: DeadlockDetector.java From mapleLemon with GNU General Public License v2.0 | 5 votes |
@Override public void run() { boolean noDeadLocks = true; while (noDeadLocks) { try { ThreadMXBean bean = ManagementFactory.getThreadMXBean(); long[] threadIds = bean.findDeadlockedThreads(); if (threadIds != null) { log.error("检测到死锁!!"); this.sb = new StringBuilder(); noDeadLocks = false; ThreadInfo[] infos = bean.getThreadInfo(threadIds); this.sb.append("\n线程锁信息: \n"); for (ThreadInfo threadInfo : infos) { printThreadInfo(threadInfo); LockInfo[] lockInfos = threadInfo.getLockedSynchronizers(); MonitorInfo[] monitorInfos = threadInfo.getLockedMonitors(); printLockInfo(lockInfos); printMonitorInfo(threadInfo, monitorInfos); } this.sb.append("\n线程转储: \n"); for (ThreadInfo ti : bean.dumpAllThreads(true, true)) { printThreadInfo(ti); } log.error(this.sb.toString()); } Thread.sleep(this.checkInterval); } catch (Exception ex) { ex.printStackTrace(); } } }
Example 8
Source File: ThreadDumper.java From aion with MIT License | 5 votes |
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(); }
Example 9
Source File: ThreadMonitor.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example 10
Source File: TestRunRecording.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Prints the owned locks for the thread. * Must have explicitly obtained Monitor and Synchronizer information for anything to show up from here. * * @param info * the {@code:ThreadInfo} for the thread in question, must not be {@code:null} * @return the owned lock information */ private static String getOwnedLockInfo(final ThreadInfo info) { StringBuilder trace = new StringBuilder(" Holding locks for:\r\n"); for (LockInfo lock : info.getLockedSynchronizers()) { trace.append(" " + lock.toString() + "\r\n"); } for (MonitorInfo monitor : info.getLockedMonitors()) { trace.append(" " + monitor.toString() + "\r\n"); } return trace.toString(); }
Example 11
Source File: ServiceTalkTestTimeout.java From servicetalk with Apache License 2.0 | 4 votes |
private static void dumpAllStacks() { ThreadMXBean bean = ManagementFactory.getThreadMXBean(); List<ThreadInfo> threadInfos = Stream.of(bean.getThreadInfo(bean.getAllThreadIds(), bean.isObjectMonitorUsageSupported(), bean.isSynchronizerUsageSupported())) .filter(Objects::nonNull) // filter out dead threads .sorted(Comparator.comparing(ThreadInfo::getThreadName)) .collect(Collectors.toList()); StringBuilder sb = new StringBuilder(threadInfos.size() * 4096); for (ThreadInfo info : threadInfos) { sb.append('"').append(info.getThreadName()).append('"'); sb.append(" #").append(info.getThreadId()); sb.append(" ").append(info.getThreadState().toString().toLowerCase()); if (info.getLockName() != null) { sb.append(" on ").append(info.getLockName()); } if (info.getLockOwnerName() != null) { sb.append(" owned by \"").append(info.getLockOwnerName()).append("\" #") .append(info.getLockOwnerId()); } if (info.isSuspended()) { sb.append(" (suspended)"); } if (info.isInNative()) { sb.append(" (in native)"); } sb.append("\n"); sb.append(" java.lang.Thread.State: ").append(info.getThreadState()).append("\n"); StackTraceElement[] stackTrace = info.getStackTrace(); for (int i = 0; i < stackTrace.length; ++i) { sb.append("\t at ").append(stackTrace[i]).append("\n"); for (MonitorInfo mi : info.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { sb.append("\t - locked ").append(mi).append("\n"); } } } sb.append("\n"); LockInfo[] locks = info.getLockedSynchronizers(); if (locks.length > 0) { sb.append("\t Number of locked synchronizers = ").append(locks.length).append("\n"); for (LockInfo li : locks) { sb.append("\t - ").append(li).append("\n"); } sb.append("\n"); } } System.out.println(sb.toString()); }
Example 12
Source File: OSProcess.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private static void formatThreadInfo(ThreadInfo t, PrintWriter pw) { // this is largely copied from the JDK's ThreadInfo.java, but it limits the // stacks to 8 elements pw.append("\"" + t.getThreadName() + "\"" + " tid=0x" + Long.toHexString(t.getThreadId())); // this is in the stack trace elements so we don't need to add it // if (t.getLockName() != null) { // pw.append(" "); // pw.append(StringUtils.toLowerCase(t.getThreadState().toString())); // pw.append(" on " + t.getLockName()); // } // priority is not known // daemon status is not known if (t.isSuspended()) { pw.append(" (suspended)"); } if (t.isInNative()) { pw.append(" (in native)"); } if (t.getLockOwnerName() != null) { pw.append(" owned by \"" + t.getLockOwnerName() + "\" tid=0x" + Long.toHexString(t.getLockOwnerId())); } pw.append('\n'); pw.append(" java.lang.Thread.State: " + t.getThreadState() + "\n"); int i = 0; StackTraceElement[] stackTrace = t.getStackTrace(); for (; i < stackTrace.length && i < MAX_STACK_FRAMES; i++) { StackTraceElement ste = stackTrace[i]; pw.append("\tat " + ste.toString()); pw.append('\n'); if (i == 0 && t.getLockInfo() != null) { Thread.State ts = t.getThreadState(); switch (ts) { case BLOCKED: pw.append("\t- blocked on " + t.getLockInfo()); pw.append('\n'); break; case WAITING: pw.append("\t- waiting on " + t.getLockInfo()); pw.append('\n'); break; case TIMED_WAITING: pw.append("\t- waiting on " + t.getLockInfo()); pw.append('\n'); break; default: } } for (MonitorInfo mi : t.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { pw.append("\t- locked " + mi); pw.append('\n'); } } } if (i < stackTrace.length) { pw.append("\t..."); pw.append('\n'); } LockInfo[] locks = t.getLockedSynchronizers(); if (locks.length > 0) { pw.append("\n\tNumber of locked synchronizers = " + locks.length); pw.append('\n'); for (LockInfo li : locks) { pw.append("\t- " + li); pw.append('\n'); } } pw.append('\n'); }
Example 13
Source File: OSProcess.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private static void formatThreadInfo(ThreadInfo t, PrintWriter pw) { // this is largely copied from the JDK's ThreadInfo.java, but it limits the // stacks to 8 elements pw.append("\"" + t.getThreadName() + "\"" + " tid=0x" + Long.toHexString(t.getThreadId())); // this is in the stack trace elements so we don't need to add it // if (t.getLockName() != null) { // pw.append(" "); // pw.append(StringUtils.toLowerCase(t.getThreadState().toString())); // pw.append(" on " + t.getLockName()); // } // priority is not known // daemon status is not known if (t.isSuspended()) { pw.append(" (suspended)"); } if (t.isInNative()) { pw.append(" (in native)"); } if (t.getLockOwnerName() != null) { pw.append(" owned by \"" + t.getLockOwnerName() + "\" tid=0x" + Long.toHexString(t.getLockOwnerId())); } pw.append('\n'); pw.append(" java.lang.Thread.State: " + t.getThreadState() + "\n"); int i = 0; StackTraceElement[] stackTrace = t.getStackTrace(); for (; i < stackTrace.length && i < MAX_STACK_FRAMES; i++) { StackTraceElement ste = stackTrace[i]; pw.append("\tat " + ste.toString()); pw.append('\n'); if (i == 0 && t.getLockInfo() != null) { Thread.State ts = t.getThreadState(); switch (ts) { case BLOCKED: pw.append("\t- blocked on " + t.getLockInfo()); pw.append('\n'); break; case WAITING: pw.append("\t- waiting on " + t.getLockInfo()); pw.append('\n'); break; case TIMED_WAITING: pw.append("\t- waiting on " + t.getLockInfo()); pw.append('\n'); break; default: } } for (MonitorInfo mi : t.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { pw.append("\t- locked " + mi); pw.append('\n'); } } } if (i < stackTrace.length) { pw.append("\t..."); pw.append('\n'); } LockInfo[] locks = t.getLockedSynchronizers(); if (locks.length > 0) { pw.append("\n\tNumber of locked synchronizers = " + locks.length); pw.append('\n'); for (LockInfo li : locks) { pw.append("\t- " + li); pw.append('\n'); } } pw.append('\n'); }
Example 14
Source File: JmxSupport.java From visualvm with GNU General Public License v2.0 | 4 votes |
private void print16Thread(final StringBuilder sb, final ThreadMXBean threadMXBean, final ThreadInfo thread) { MonitorInfo[] monitors = null; if (threadMXBean.isObjectMonitorUsageSupported()) { monitors = thread.getLockedMonitors(); } sb.append("\n\"" + thread.getThreadName() + // NOI18N "\" - Thread t@" + thread.getThreadId() + "\n"); // NOI18N sb.append(" java.lang.Thread.State: " + thread.getThreadState()); // NOI18N sb.append("\n"); // NOI18N int index = 0; for (StackTraceElement st : thread.getStackTrace()) { LockInfo lock = thread.getLockInfo(); String lockOwner = thread.getLockOwnerName(); sb.append("\tat " + st.toString() + "\n"); // NOI18N if (index == 0) { if ("java.lang.Object".equals(st.getClassName()) && // NOI18N "wait".equals(st.getMethodName())) { // NOI18N if (lock != null) { sb.append("\t- waiting on "); // NOI18N printLock(sb,lock); sb.append("\n"); // NOI18N } } else if (lock != null) { if (lockOwner == null) { sb.append("\t- parking to wait for "); // NOI18N printLock(sb,lock); sb.append("\n"); // NOI18N } else { sb.append("\t- waiting to lock "); // NOI18N printLock(sb,lock); sb.append(" owned by \""+lockOwner+"\" t@"+thread.getLockOwnerId()+"\n"); // NOI18N } } } printMonitors(sb, monitors, index); index++; } StringBuilder jnisb = new StringBuilder(); printMonitors(jnisb, monitors, -1); if (jnisb.length() > 0) { sb.append(" JNI locked monitors:\n"); sb.append(jnisb); } if (threadMXBean.isSynchronizerUsageSupported()) { sb.append("\n Locked ownable synchronizers:"); // NOI18N LockInfo[] synchronizers = thread.getLockedSynchronizers(); if (synchronizers == null || synchronizers.length == 0) { sb.append("\n\t- None\n"); // NOI18N } else { for (LockInfo li : synchronizers) { sb.append("\n\t- locked "); // NOI18N printLock(sb,li); sb.append("\n"); // NOI18N } } } }
Example 15
Source File: ThreadDump.java From metrics with Apache License 2.0 | 4 votes |
/** * Dumps all of the threads' current information to an output stream. * * @param out an output stream */ public void dump(OutputStream out) { final ThreadInfo[] threads = this.threadMXBean.dumpAllThreads(true, true); final PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, UTF_8)); for (int ti = threads.length - 1; ti >= 0; ti--) { final ThreadInfo t = threads[ti]; writer.printf("%s id=%d state=%s", t.getThreadName(), t.getThreadId(), t.getThreadState()); final LockInfo lock = t.getLockInfo(); if (lock != null && t.getThreadState() != Thread.State.BLOCKED) { writer.printf("%n - waiting on <0x%08x> (a %s)", lock.getIdentityHashCode(), lock.getClassName()); writer.printf("%n - locked <0x%08x> (a %s)", lock.getIdentityHashCode(), lock.getClassName()); } else if (lock != null && t.getThreadState() == Thread.State.BLOCKED) { writer.printf("%n - waiting to lock <0x%08x> (a %s)", lock.getIdentityHashCode(), lock.getClassName()); } if (t.isSuspended()) { writer.print(" (suspended)"); } if (t.isInNative()) { writer.print(" (running in native)"); } writer.println(); if (t.getLockOwnerName() != null) { writer.printf(" owned by %s id=%d%n", t.getLockOwnerName(), t.getLockOwnerId()); } final StackTraceElement[] elements = t.getStackTrace(); final MonitorInfo[] monitors = t.getLockedMonitors(); for (int i = 0; i < elements.length; i++) { final StackTraceElement element = elements[i]; writer.printf(" at %s%n", element); for (int j = 1; j < monitors.length; j++) { final MonitorInfo monitor = monitors[j]; if (monitor.getLockedStackDepth() == i) { writer.printf(" - locked %s%n", monitor); } } } writer.println(); final LockInfo[] locks = t.getLockedSynchronizers(); if (locks.length > 0) { writer.printf(" Locked synchronizers: count = %d%n", locks.length); for (LockInfo l : locks) { writer.printf(" - %s%n", l); } writer.println(); } } writer.println(); writer.flush(); }
Example 16
Source File: SdcInfoContentGenerator.java From datacollector with Apache License 2.0 | 4 votes |
public void threadDump(BundleWriter writer) throws IOException { writer.markStartOfFile("runtime/threads.txt"); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threads = threadMXBean.dumpAllThreads(true, true); // Sadly we can't easily do info.toString() as the implementation is hardcoded to cut the stack trace only to 8 // items which does not serve our purpose well. Hence we have custom implementation that prints entire stack trace // for all threads. for(ThreadInfo info: threads) { 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'); int i = 0; for(StackTraceElement ste : info.getStackTrace()) { if (i == 0 && info.getLockInfo() != null) { Thread.State ts = info.getThreadState(); switch (ts) { case BLOCKED: sb.append("\t- blocked on " + info.getLockInfo()); sb.append('\n'); break; case WAITING: sb.append("\t- waiting on " + info.getLockInfo()); sb.append('\n'); break; case TIMED_WAITING: sb.append("\t- waiting on " + info.getLockInfo()); sb.append('\n'); break; default: } } sb.append("\tat " + ste.toString()); sb.append('\n'); i++; for (MonitorInfo mi : info.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { sb.append("\t- locked " + mi); sb.append('\n'); } } } 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'); writer.write(sb.toString()); } writer.markEndOfFile(); }
Example 17
Source File: TestConfigurationLock.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static String asString(ThreadInfo inf) { StringBuilder sb = new StringBuilder(); sb.append("\"").append(inf.getThreadName()).append("\"") .append(inf.isDaemon() ? " daemon" : "") .append(" prio=").append(inf.getPriority()) .append(" Id=").append(inf.getThreadId()) .append(" ").append(inf.getThreadState()); if (inf.getLockName() != null) { sb.append(" on ").append(inf.getLockName()); } if (inf.getLockOwnerName() != null) { sb.append(" owned by \"").append(inf.getLockOwnerName()) .append("\" Id=").append(inf.getLockOwnerId()); } if (inf.isSuspended()) { sb.append(" (suspended)"); } if (inf.isInNative()) { sb.append(" (in native)"); } sb.append('\n'); int i = 0; StackTraceElement[] stackTrace = inf.getStackTrace(); for (; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace[i]; sb.append("\tat ").append(ste.toString()); sb.append('\n'); if (i == 0 && inf.getLockInfo() != null) { Thread.State ts = inf.getThreadState(); switch (ts) { case BLOCKED: sb.append("\t- blocked on ").append(inf.getLockInfo()); sb.append('\n'); break; case WAITING: sb.append("\t- waiting on ").append(inf.getLockInfo()); sb.append('\n'); break; case TIMED_WAITING: sb.append("\t- waiting on ").append(inf.getLockInfo()); sb.append('\n'); break; default: } } for (MonitorInfo mi : inf.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { sb.append("\t- locked ").append(mi); sb.append('\n'); } } } if (i < stackTrace.length) { sb.append("\t..."); sb.append('\n'); } LockInfo[] locks = inf.getLockedSynchronizers(); if (locks.length > 0) { sb.append("\n\tNumber of locked synchronizers = ").append(locks.length); sb.append('\n'); for (LockInfo li : locks) { sb.append("\t- ").append(li); sb.append('\n'); } } sb.append('\n'); return sb.toString(); }
Example 18
Source File: AbstractContainer.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private String getThreadStackTraces(final ThreadInfo threadInfo) { String lineSeparator = System.lineSeparator(); StringBuilder dump = new StringBuilder(); dump.append("\"").append(threadInfo.getThreadName()).append("\"").append(" Id=") .append(threadInfo.getThreadId()).append( " ").append(threadInfo.getThreadState()); if (threadInfo.getLockName() != null) { dump.append(" on ").append(threadInfo.getLockName()); } if (threadInfo.getLockOwnerName() != null) { dump.append(" owned by \"").append(threadInfo.getLockOwnerName()) .append("\" Id=").append(threadInfo.getLockOwnerId()); } if (threadInfo.isSuspended()) { dump.append(" (suspended)"); } if (threadInfo.isInNative()) { dump.append(" (in native)"); } dump.append(lineSeparator); StackTraceElement[] stackTrace = threadInfo.getStackTrace(); for (int i = 0; i < stackTrace.length; i++) { StackTraceElement stackTraceElement = stackTrace[i]; dump.append(" at ").append(stackTraceElement.toString()).append(lineSeparator); LockInfo lockInfo = threadInfo.getLockInfo(); if (i == 0 && lockInfo != null) { Thread.State threadState = threadInfo.getThreadState(); switch (threadState) { case BLOCKED: dump.append(" - blocked on ").append(lockInfo).append(lineSeparator); break; case WAITING: dump.append(" - waiting on ").append(lockInfo).append(lineSeparator); break; case TIMED_WAITING: dump.append(" - waiting on ").append(lockInfo).append(lineSeparator); break; default: } } for (MonitorInfo mi : threadInfo.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { dump.append(" - locked ").append(mi).append(lineSeparator); } } } LockInfo[] locks = threadInfo.getLockedSynchronizers(); if (locks.length > 0) { dump.append(lineSeparator).append(" Number of locked synchronizers = ").append(locks.length); dump.append(lineSeparator); for (LockInfo li : locks) { dump.append(" - " + li); dump.append(lineSeparator); } } dump.append(lineSeparator); return dump.toString(); }
Example 19
Source File: ThreadUtil.java From samza with Apache License 2.0 | 4 votes |
/** * Copy of ThreadInfo#toString() without the hardcoded MAX_FRAMES = 8 restriction on thread stack depth. * * Returns a string representation of this thread info. * The format of this string depends on the implementation. * The returned string will typically include * the thread name, the getThreadId thread ID, its state, * and a stack trace if any. * * @return a string representation of this thread info. */ private static String toString(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'); int i = 0; for (; i < info.getStackTrace().length; i++) { StackTraceElement ste = info.getStackTrace()[i]; sb.append("\tat " + ste.toString()); sb.append('\n'); if (i == 0 && info.getLockInfo() != null) { Thread.State ts = info.getThreadState(); switch (ts) { case BLOCKED: sb.append("\t- blocked on " + info.getLockInfo()); sb.append('\n'); break; case WAITING: sb.append("\t- waiting on " + info.getLockInfo()); sb.append('\n'); break; case TIMED_WAITING: sb.append("\t- waiting on " + info.getLockInfo()); sb.append('\n'); break; default: } } for (MonitorInfo mi : info.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { sb.append("\t- locked " + mi); sb.append('\n'); } } } if (i < info.getStackTrace().length) { sb.append("\t..."); sb.append('\n'); } 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(); }
Example 20
Source File: GfxdLocalLockService.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void generateThreadDump(StringBuilder msg) { ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); for (ThreadInfo tInfo : mbean.dumpAllThreads(true, true)) { msg.append('"').append(tInfo.getThreadName()).append('"').append(" Id=") .append(tInfo.getThreadId()).append(' ') .append(tInfo.getThreadState()); if (tInfo.getLockName() != null) { msg.append(" on ").append(tInfo.getLockName()); } if (tInfo.getLockOwnerName() != null) { msg.append(" owned by \"").append(tInfo.getLockOwnerName()) .append("\" Id=").append(tInfo.getLockOwnerId()); } if (tInfo.isSuspended()) { msg.append(" (suspended)"); } if (tInfo.isInNative()) { msg.append(" (in native)"); } msg.append(SanityManager.lineSeparator); final StackTraceElement[] stackTrace = tInfo.getStackTrace(); for (int index = 0; index < stackTrace.length; ++index) { msg.append("\tat ").append(stackTrace[index].toString()) .append(SanityManager.lineSeparator); if (index == 0 && tInfo.getLockInfo() != null) { final Thread.State ts = tInfo.getThreadState(); switch (ts) { case BLOCKED: msg.append("\t- blocked on ").append(tInfo.getLockInfo()) .append(SanityManager.lineSeparator); break; case WAITING: msg.append("\t- waiting on ").append(tInfo.getLockInfo()) .append(SanityManager.lineSeparator); break; case TIMED_WAITING: msg.append("\t- waiting on ").append(tInfo.getLockInfo()) .append(SanityManager.lineSeparator); break; default: } } for (MonitorInfo mi : tInfo.getLockedMonitors()) { if (mi.getLockedStackDepth() == index) { msg.append("\t- locked ").append(mi) .append(SanityManager.lineSeparator); } } } final LockInfo[] locks = tInfo.getLockedSynchronizers(); if (locks.length > 0) { msg.append(SanityManager.lineSeparator) .append("\tNumber of locked synchronizers = ").append(locks.length) .append(SanityManager.lineSeparator); for (LockInfo li : locks) { msg.append("\t- ").append(li).append(SanityManager.lineSeparator); } } msg.append(SanityManager.lineSeparator); } }