Java Code Examples for java.lang.management.ThreadInfo#getLockName()
The following examples show how to use
java.lang.management.ThreadInfo#getLockName() .
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: TimedOutTestsListener.java From hadoop-ozone with Apache License 2.0 | 6 votes |
private static void printThread(ThreadInfo ti, PrintWriter out) { out.print("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState()); if (ti.getLockName() != null) { out.print(" on lock=" + ti.getLockName()); } if (ti.isSuspended()) { out.print(" (suspended)"); } if (ti.isInNative()) { out.print(" (running in native)"); } out.println(); if (ti.getLockOwnerName() != null) { out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()); } }
Example 2
Source File: ThreadMonitor.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void printThread(ThreadInfo ti) { StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState()); if (ti.getLockName() != null) { sb.append(" on lock=" + ti.getLockName()); } if (ti.isSuspended()) { sb.append(" (suspended)"); } if (ti.isInNative()) { sb.append(" (running in native)"); } System.out.println(sb.toString()); if (ti.getLockOwnerName() != null) { System.out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()); } }
Example 3
Source File: ThreadDumpingWatchdog.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private static void dumpThreadHeader(StringBuilder sb, ThreadInfo tinfo) { sb.append('"').append(tinfo.getThreadName()).append("\" [").append(tinfo.getThreadId()) .append("] ").append(tinfo.getThreadState()); if (tinfo.getLockName() != null) { sb.append(" on ").append(tinfo.getLockName()); } if (tinfo.getLockOwnerName() != null) { sb.append(" owned by '").append(tinfo.getLockOwnerName()).append(" [id:") .append(tinfo.getLockOwnerId()).append(']'); } if (tinfo.isSuspended()) { sb.append(" (suspended)"); } if (tinfo.isInNative()) { sb.append(" (in native code)"); } }
Example 4
Source File: TimedOutTestsListener.java From hbase with Apache License 2.0 | 6 votes |
private static void printThread(ThreadInfo ti, PrintWriter out) { out.print("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState()); if (ti.getLockName() != null) { out.print(" on lock=" + ti.getLockName()); } if (ti.isSuspended()) { out.print(" (suspended)"); } if (ti.isInNative()) { out.print(" (running in native)"); } out.println(); if (ti.getLockOwnerName() != null) { out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()); } }
Example 5
Source File: ThreadDumpWindow.java From visualvm with GNU General Public License v2.0 | 6 votes |
private void print15Thread(final StringBuilder sb, final ThreadInfo thread, boolean goToSourceAvailable) { sb.append("<br>\"" + thread.getThreadName() + // NOI18N "\" - Thread t@" + thread.getThreadId() + "<br>"); // NOI18N sb.append(" java.lang.Thread.State: " + thread.getThreadState()); // NOI18N if (thread.getLockName() != null) { sb.append(" on " + thread.getLockName()); // NOI18N if (thread.getLockOwnerName() != null) { sb.append(" owned by: " + thread.getLockOwnerName()); // NOI18N } } sb.append("<br>"); // NOI18N for (StackTraceElement st : thread.getStackTrace()) { String stackElementText = htmlize(st.toString()); String stackEl = stackElementText; if (goToSourceAvailable) { String className = st.getClassName(); String method = st.getMethodName(); int lineNo = st.getLineNumber(); String stackUrl = OPEN_THREADS_URL + className + "|" + method + "|" + lineNo; // NOI18N stackEl = "<a href=\"" + stackUrl + "\">" + stackElementText + "</a>"; // NOI18N } sb.append(" at ").append(stackEl).append("<br>"); // NOI18N } }
Example 6
Source File: ThreadMonitor.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void printThread(ThreadInfo ti) { StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState()); if (ti.getLockName() != null) { sb.append(" on lock=" + ti.getLockName()); } if (ti.isSuspended()) { sb.append(" (suspended)"); } if (ti.isInNative()) { sb.append(" (running in native)"); } System.out.println(sb.toString()); if (ti.getLockOwnerName() != null) { System.out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()); } }
Example 7
Source File: ThreadDumpAction.java From emissary with Apache License 2.0 | 6 votes |
public ThreadDumpInfo(ThreadInfo ti) { StringBuilder sb = new StringBuilder(); if (ti == null) { sb.append("A null thread?"); } else { sb.append("\"" + ti.getThreadName() + "\" tid=" + ti.getThreadId() + "\n"); sb.append(" thread state " + ti.getThreadState()); // no new line if (ti.getLockName() != null) { sb.append(" (on " + ti.getLockName() + " owned by " + ti.getLockOwnerId() + ")\n"); } if (ti.isSuspended()) { sb.append(" SUSPENDED\n"); } if (ti.isInNative()) { sb.append(" IN NATIVE CODE\n"); } for (StackTraceElement ste : ti.getStackTrace()) { sb.append(" " + ste.toString() + "\n"); } } stack = sb.toString(); }
Example 8
Source File: ThreadMonitor.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private void printThread(ThreadInfo ti) { StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState()); if (ti.getLockName() != null) { sb.append(" on lock=" + ti.getLockName()); } if (ti.isSuspended()) { sb.append(" (suspended)"); } if (ti.isInNative()) { sb.append(" (running in native)"); } System.out.println(sb.toString()); if (ti.getLockOwnerName() != null) { System.out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()); } }
Example 9
Source File: JSR166TestCase.java From streamsupport with GNU General Public License v2.0 | 5 votes |
/** * A debugging tool to print stack traces of most threads, as jstack does. * Uninteresting threads are filtered out. */ static void dumpTestThreads() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { try { System.setSecurityManager(null); } catch (SecurityException giveUp) { return; } } ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); System.err.println("------ stacktrace dump start ------"); for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { final String name = info.getThreadName(); String lockName; if ("Signal Dispatcher".equals(name)) continue; if ("Reference Handler".equals(name) && (lockName = info.getLockName()) != null && lockName.startsWith("java.lang.ref.Reference$Lock")) continue; if ("Finalizer".equals(name) && (lockName = info.getLockName()) != null && lockName.startsWith("java.lang.ref.ReferenceQueue$Lock")) continue; if ("checkForWedgedTest".equals(name)) continue; System.err.print(info); } System.err.println("------ stacktrace dump end ------"); if (sm != null) System.setSecurityManager(sm); }
Example 10
Source File: DiagnosticUtility.java From terracotta-platform with Apache License 2.0 | 5 votes |
private static void threadHeader(StringBuilder sb, ThreadInfo threadInfo) { final String threadName = threadInfo.getThreadName(); sb.append("\""); sb.append(threadName); sb.append("\" "); sb.append("Id="); sb.append(threadInfo.getThreadId()); try { final Thread.State threadState = threadInfo.getThreadState(); final String lockName = threadInfo.getLockName(); final String lockOwnerName = threadInfo.getLockOwnerName(); final Long lockOwnerId = threadInfo.getLockOwnerId(); final Boolean isSuspended = threadInfo.isSuspended(); final Boolean isInNative = threadInfo.isInNative(); sb.append(" "); sb.append(threadState); if (lockName != null) { sb.append(" on "); sb.append(lockName); } if (lockOwnerName != null) { sb.append(" owned by \""); sb.append(lockOwnerName); sb.append("\" Id="); sb.append(lockOwnerId); } if (isSuspended) { sb.append(" (suspended)"); } if (isInNative) { sb.append(" (in native)"); } } catch (final Exception e) { sb.append(" ( Got exception : ").append(e.getMessage()).append(" :"); } sb.append('\n'); }
Example 11
Source File: Diagnostics.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * 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(); }
Example 12
Source File: NativeProtocol.java From lams with GNU General Public License v2.0 | 4 votes |
private void appendDeadlockStatusInformation(Session sess, String xOpen, StringBuilder errorBuf) { if (sess.getPropertySet().getBooleanReadableProperty(PropertyDefinitions.PNAME_includeInnodbStatusInDeadlockExceptions).getValue() && xOpen != null && (xOpen.startsWith("40") || xOpen.startsWith("41")) && getStreamingData() == null) { try { NativePacketPayload resultPacket = sendCommand(this.commandBuilder.buildComQuery(getSharedSendPacket(), "SHOW ENGINE INNODB STATUS"), false, 0); Resultset rs = readAllResults(-1, false, resultPacket, false, null, new ResultsetFactory(Type.FORWARD_ONLY, null)); int colIndex = 0; Field f = null; for (int i = 0; i < rs.getColumnDefinition().getFields().length; i++) { f = rs.getColumnDefinition().getFields()[i]; if ("Status".equals(f.getName())) { colIndex = i; break; } } ValueFactory<String> vf = new StringValueFactory(f.getEncoding()); Row r; if ((r = rs.getRows().next()) != null) { errorBuf.append("\n\n").append(r.getValue(colIndex, vf)); } else { errorBuf.append("\n\n").append(Messages.getString("MysqlIO.NoInnoDBStatusFound")); } } catch (IOException | CJException ex) { errorBuf.append("\n\n").append(Messages.getString("MysqlIO.InnoDBStatusFailed")).append("\n\n").append(Util.stackTraceToString(ex)); } } if (sess.getPropertySet().getBooleanReadableProperty(PropertyDefinitions.PNAME_includeThreadDumpInDeadlockExceptions).getValue()) { errorBuf.append("\n\n*** Java threads running at time of deadlock ***\n\n"); ThreadMXBean threadMBean = ManagementFactory.getThreadMXBean(); long[] threadIds = threadMBean.getAllThreadIds(); ThreadInfo[] threads = threadMBean.getThreadInfo(threadIds, Integer.MAX_VALUE); List<ThreadInfo> activeThreads = new ArrayList<>(); for (ThreadInfo info : threads) { if (info != null) { activeThreads.add(info); } } for (ThreadInfo threadInfo : activeThreads) { // "Thread-60" daemon prio=1 tid=0x093569c0 nid=0x1b99 in Object.wait() errorBuf.append('"').append(threadInfo.getThreadName()).append("\" tid=").append(threadInfo.getThreadId()).append(" ") .append(threadInfo.getThreadState()); if (threadInfo.getLockName() != null) { errorBuf.append(" on lock=").append(threadInfo.getLockName()); } if (threadInfo.isSuspended()) { errorBuf.append(" (suspended)"); } if (threadInfo.isInNative()) { errorBuf.append(" (running in native)"); } StackTraceElement[] stackTrace = threadInfo.getStackTrace(); if (stackTrace.length > 0) { errorBuf.append(" in "); errorBuf.append(stackTrace[0].getClassName()).append("."); errorBuf.append(stackTrace[0].getMethodName()).append("()"); } errorBuf.append("\n"); if (threadInfo.getLockOwnerName() != null) { errorBuf.append("\t owned by ").append(threadInfo.getLockOwnerName()).append(" Id=").append(threadInfo.getLockOwnerId()).append("\n"); } for (int j = 0; j < stackTrace.length; j++) { StackTraceElement ste = stackTrace[j]; errorBuf.append("\tat ").append(ste.toString()).append("\n"); } } } }
Example 13
Source File: ThreadMXBeanStateTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private static void checkLockInfo(ThreadStateController t, Thread.State state, Object lock, Thread owner) { ThreadInfo info = getThreadInfo(t, state); if (info == null) { throw new RuntimeException(t.getName() + " expected to have ThreadInfo " + " but got null."); } if (info.getThreadState() != state) { throw new RuntimeException(t.getName() + " expected to be in " + state + " state but got " + info.getThreadState()); } if (lock == null && info.getLockName() != null) { throw new RuntimeException(t.getName() + " expected not to be blocked on any lock" + " but got " + info.getLockName()); } String expectedLockName = getLockName(lock); if (lock != null && info.getLockName() == null) { throw new RuntimeException(t.getName() + " expected to be blocked on lock [" + expectedLockName + "] but got null."); } if (lock != null && !expectedLockName.equals(info.getLockName())) { throw new RuntimeException(t.getName() + " expected to be blocked on lock [" + expectedLockName + "] but got [" + info.getLockName() + "]."); } if (owner == null && info.getLockOwnerName() != null) { throw new RuntimeException("Lock owner is expected " + " to be null but got " + info.getLockOwnerName()); } if (owner != null && info.getLockOwnerName() == null) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + " but got null."); } if (owner != null && !info.getLockOwnerName().equals(owner.getName())) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + " but got " + owner.getName()); } if (owner == null && info.getLockOwnerId() != -1) { throw new RuntimeException("Lock owner is expected " + " to be -1 but got " + info.getLockOwnerId()); } if (owner != null && info.getLockOwnerId() <= 0) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + "(id = " + owner.getId() + ") but got " + info.getLockOwnerId()); } if (owner != null && info.getLockOwnerId() != owner.getId()) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + "(id = " + owner.getId() + ") but got " + info.getLockOwnerId()); } if (info.isSuspended()) { throw new RuntimeException(t.getName() + " isSuspended() returns " + info.isSuspended()); } }
Example 14
Source File: ThreadMXBeanStateTest.java From hottub with GNU General Public License v2.0 | 4 votes |
private static void checkLockInfo(ThreadStateController t, Thread.State state, Object lock, Thread owner) { ThreadInfo info = getThreadInfo(t, state); if (info == null) { throw new RuntimeException(t.getName() + " expected to have ThreadInfo " + " but got null."); } if (info.getThreadState() != state) { throw new RuntimeException(t.getName() + " expected to be in " + state + " state but got " + info.getThreadState()); } if (lock == null && info.getLockName() != null) { throw new RuntimeException(t.getName() + " expected not to be blocked on any lock" + " but got " + info.getLockName()); } String expectedLockName = getLockName(lock); if (lock != null && info.getLockName() == null) { throw new RuntimeException(t.getName() + " expected to be blocked on lock [" + expectedLockName + "] but got null."); } if (lock != null && !expectedLockName.equals(info.getLockName())) { throw new RuntimeException(t.getName() + " expected to be blocked on lock [" + expectedLockName + "] but got [" + info.getLockName() + "]."); } if (owner == null && info.getLockOwnerName() != null) { throw new RuntimeException("Lock owner is expected " + " to be null but got " + info.getLockOwnerName()); } if (owner != null && info.getLockOwnerName() == null) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + " but got null."); } if (owner != null && !info.getLockOwnerName().equals(owner.getName())) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + " but got " + owner.getName()); } if (owner == null && info.getLockOwnerId() != -1) { throw new RuntimeException("Lock owner is expected " + " to be -1 but got " + info.getLockOwnerId()); } if (owner != null && info.getLockOwnerId() <= 0) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + "(id = " + owner.getId() + ") but got " + info.getLockOwnerId()); } if (owner != null && info.getLockOwnerId() != owner.getId()) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + "(id = " + owner.getId() + ") but got " + info.getLockOwnerId()); } if (info.isSuspended()) { throw new RuntimeException(t.getName() + " isSuspended() returns " + info.isSuspended()); } }
Example 15
Source File: ThreadDumpUtil.java From activemq-artemis with Apache License 2.0 | 4 votes |
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(); }
Example 16
Source File: ThreadInfoCompositeData.java From native-obfuscator with GNU General Public License v3.0 | 4 votes |
static void checkThreadInfo(ThreadInfo info) throws Exception { if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) { throw new RuntimeException("Thread Id = " + info.getThreadId() + " expected = " + values[THREAD_ID]); } if (!info.getThreadName().equals(values[THREAD_NAME])) { throw new RuntimeException("Thread Name = " + info.getThreadName() + " expected = " + values[THREAD_NAME]); } if (info.getThreadState() != Thread.State.RUNNABLE) { throw new RuntimeException("Thread Name = " + info.getThreadName() + " expected = " + Thread.State.RUNNABLE); } if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) { throw new RuntimeException("blocked time = " + info.getBlockedTime() + " expected = " + values[BLOCKED_TIME]); } if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) { throw new RuntimeException("blocked count = " + info.getBlockedCount() + " expected = " + values[BLOCKED_COUNT]); } if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) { throw new RuntimeException("waited time = " + info.getWaitedTime() + " expected = " + values[WAITED_TIME]); } if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) { throw new RuntimeException("waited count = " + info.getWaitedCount() + " expected = " + values[WAITED_COUNT]); } if (!info.getLockName().equals(values[LOCK_NAME])) { throw new RuntimeException("Lock Name = " + info.getLockName() + " expected = " + values[LOCK_NAME]); } if (info.getLockOwnerId() != ((Long) values[LOCK_OWNER_ID]).longValue()) { throw new RuntimeException( "LockOwner Id = " + info.getLockOwnerId() + " expected = " + values[LOCK_OWNER_ID]); } if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) { throw new RuntimeException("LockOwner Name = " + info.getLockOwnerName() + " expected = " + values[LOCK_OWNER_NAME]); } checkStackTrace(info.getStackTrace()); checkLockInfo(info.getLockInfo()); }
Example 17
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 18
Source File: ThreadDumpPro.java From baratine with GNU General Public License v2.0 | 4 votes |
protected void buildThread(StringBuilder sb, ThreadInfo info) { sb.append("\n\""); sb.append(info.getThreadName()); sb.append("\" id=" + info.getThreadId()); sb.append(" " + info.getThreadState()); if (info.isInNative()) sb.append(" (in native)"); if (info.isSuspended()) sb.append(" (suspended)"); String lockName = info.getLockName(); if (lockName != null) { sb.append("\n waiting on "); sb.append(lockName); if (info.getLockOwnerName() != null) { sb.append("\n owned by \""); sb.append(info.getLockOwnerName()); sb.append("\""); } } sb.append("\n"); NetworkSystemBartender networkSystem = NetworkSystemBartender.current(); if (networkSystem != null) { ConnectionTcp conn = networkSystem.findConnectionByThreadId(info.getThreadId()); if (conn != null && conn.connProtocol() instanceof RequestHttpBase) { RequestHttpBase req = (RequestHttpBase) conn.connProtocol(); if (true) throw new UnsupportedOperationException(); /* XXX: if (req.getRequestURI() != null) { sb.append(" ").append(req.getRequestURI()).append("\n"); } */ } } StackTraceElement []stackList = info.getStackTrace(); if (stackList == null) return; for (StackTraceElement stack : stackList) { sb.append(" at "); sb.append(stack.getClassName()); sb.append("."); sb.append(stack.getMethodName()); if (stack.getFileName() != null) { sb.append(" ("); sb.append(stack.getFileName()); if (stack.getLineNumber() > 0) { sb.append(":"); sb.append(stack.getLineNumber()); } sb.append(")"); } if (stack.isNativeMethod()) sb.append(" (native)"); sb.append("\n"); } }
Example 19
Source File: ThreadMXBeanStateTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private static void checkLockInfo(ThreadStateController t, Thread.State state, Object lock, Thread owner) { ThreadInfo info = getThreadInfo(t, state); if (info == null) { throw new RuntimeException(t.getName() + " expected to have ThreadInfo " + " but got null."); } if (info.getThreadState() != state) { throw new RuntimeException(t.getName() + " expected to be in " + state + " state but got " + info.getThreadState()); } if (lock == null && info.getLockName() != null) { throw new RuntimeException(t.getName() + " expected not to be blocked on any lock" + " but got " + info.getLockName()); } String expectedLockName = getLockName(lock); if (lock != null && info.getLockName() == null) { throw new RuntimeException(t.getName() + " expected to be blocked on lock [" + expectedLockName + "] but got null."); } if (lock != null && !expectedLockName.equals(info.getLockName())) { throw new RuntimeException(t.getName() + " expected to be blocked on lock [" + expectedLockName + "] but got [" + info.getLockName() + "]."); } if (owner == null && info.getLockOwnerName() != null) { throw new RuntimeException("Lock owner is expected " + " to be null but got " + info.getLockOwnerName()); } if (owner != null && info.getLockOwnerName() == null) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + " but got null."); } if (owner != null && !info.getLockOwnerName().equals(owner.getName())) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + " but got " + owner.getName()); } if (owner == null && info.getLockOwnerId() != -1) { throw new RuntimeException("Lock owner is expected " + " to be -1 but got " + info.getLockOwnerId()); } if (owner != null && info.getLockOwnerId() <= 0) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + "(id = " + owner.getId() + ") but got " + info.getLockOwnerId()); } if (owner != null && info.getLockOwnerId() != owner.getId()) { throw new RuntimeException("Lock owner is expected to be " + owner.getName() + "(id = " + owner.getId() + ") but got " + info.getLockOwnerId()); } if (info.isSuspended()) { throw new RuntimeException(t.getName() + " isSuspended() returns " + info.isSuspended()); } }
Example 20
Source File: DeadlockMonitorTask.java From pinpoint with Apache License 2.0 | 4 votes |
/** * 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(); }