Java Code Examples for java.lang.management.ThreadInfo#getLockOwnerName()
The following examples show how to use
java.lang.management.ThreadInfo#getLockOwnerName() .
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: NbTestCase.java From netbeans with Apache License 2.0 | 6 votes |
private static StringBuilder printThread(ThreadInfo ti, StringBuilder sb) { sb.append("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState()); if (ti.getLockName() != null) { sb.append(" waiting on lock=" + ti.getLockName()); } if (ti.isSuspended()) { sb.append(" (suspended)"); } if (ti.isInNative()) { sb.append(" (running in native)"); } sb.append("\n"); if (ti.getLockOwnerName() != null) { sb.append("\t owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()).append("\n"); } return sb; }
Example 2
Source File: DeadlockDetector.java From mapleLemon with GNU General Public License v2.0 | 6 votes |
private void printThread(ThreadInfo ti) { this.sb.append("\nPrintThread\n"); this.sb.append("\"").append(ti.getThreadName()).append("\" Id=").append(ti.getThreadId()).append(" in ").append(ti.getThreadState()).append("\n"); if (ti.getLockName() != null) { this.sb.append(" on lock=").append(ti.getLockName()).append("\n"); } if (ti.isSuspended()) { this.sb.append(" (suspended)\n"); } if (ti.isInNative()) { this.sb.append(" (running in native)\n"); } if (ti.getLockOwnerName() != null) { this.sb.append(INDENT).append(" owned by ").append(ti.getLockOwnerName()).append(" Id=").append(ti.getLockOwnerId()).append("\n"); } }
Example 3
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 4
Source File: ThreadMonitor.java From hottub 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 5
Source File: TimedOutTestsListener.java From big-c 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 6
Source File: ThreadMonitor.java From openjdk-8-source 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: ThreadMonitor.java From jdk8u-dev-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 8
Source File: JmxSupport.java From visualvm with GNU General Public License v2.0 | 5 votes |
private void print15Thread(final StringBuilder sb, final ThreadInfo thread) { sb.append("\n\"" + thread.getThreadName() + // NOI18N "\" - Thread t@" + thread.getThreadId() + "\n"); // 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("\n"); // NOI18N for (StackTraceElement st : thread.getStackTrace()) { sb.append(" at " + st.toString() + "\n"); // NOI18N } }
Example 9
Source File: DeadlockInfo.java From reef with Apache License 2.0 | 5 votes |
/** * Get a string identifying the lock that this thread is waiting on. * @param threadInfo * @return A string identifying the lock that this thread is waiting on, * or null if the thread is not waiting on a lock */ @Nullable public String getWaitingLockString(final ThreadInfo threadInfo) { if (null == threadInfo.getLockInfo()) { return null; } else { return threadInfo.getLockName() + " held by " + threadInfo.getLockOwnerName(); } }
Example 10
Source File: ThreadDumpHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private static SimpleOrderedMap<Object> getThreadInfo( ThreadInfo ti, ThreadMXBean tmbean ) { SimpleOrderedMap<Object> info = new SimpleOrderedMap<>(); long tid = ti.getThreadId(); info.add( ID, tid ); info.add(NAME, ti.getThreadName()); info.add( "state", ti.getThreadState().toString() ); if (ti.getLockName() != null) { info.add( "lock", ti.getLockName() ); } if (ti.isSuspended()) { info.add( "suspended", true ); } if (ti.isInNative()) { info.add( "native", true ); } if (tmbean.isThreadCpuTimeSupported()) { info.add( "cpuTime", formatNanos(tmbean.getThreadCpuTime(tid)) ); info.add( "userTime", formatNanos(tmbean.getThreadUserTime(tid)) ); } if (ti.getLockOwnerName() != null) { SimpleOrderedMap<Object> owner = new SimpleOrderedMap<>(); owner.add(NAME, ti.getLockOwnerName()); owner.add( ID, ti.getLockOwnerId() ); } // Add the stack trace int i=0; String[] trace = new String[ti.getStackTrace().length]; for( StackTraceElement ste : ti.getStackTrace()) { trace[i++] = ste.toString(); } info.add( "stackTrace", trace ); return info; }
Example 11
Source File: ThreadMXBeanStateTest.java From jdk8u-dev-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 12
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 13
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 14
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(); }
Example 15
Source File: ThreadMXBeanStateTest.java From openjdk-8 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 16
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 17
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 18
Source File: StackTraces.java From bazel with Apache License 2.0 | 4 votes |
private static void dumpThreadInfo(ThreadInfo t, Thread thread, PrintStream out) { out.print("\"" + t.getThreadName() + "\"" + " Id=" + t.getThreadId() + " " + t.getThreadState()); if (t.getLockName() != null) { out.print(" on " + t.getLockName()); } if (t.getLockOwnerName() != null) { out.print(" owned by \"" + t.getLockOwnerName() + "\" Id=" + t.getLockOwnerId()); } if (t.isSuspended()) { out.print(" (suspended)"); } if (t.isInNative()) { out.print(" (in native)"); } if (thread.isDaemon()) { out.print(" (daemon)"); } out.print('\n'); StackTraceElement[] stackTrace = t.getStackTrace(); MonitorInfo[] lockedMonitors = t.getLockedMonitors(); for (int i = 0; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace[i]; out.print("\tat " + ste.toString()); out.print('\n'); if (i == 0 && t.getLockInfo() != null) { Thread.State ts = t.getThreadState(); switch (ts) { case BLOCKED: out.print("\t- blocked on " + t.getLockInfo()); out.print('\n'); break; case WAITING: out.print("\t- waiting on " + t.getLockInfo()); out.print('\n'); break; case TIMED_WAITING: out.print("\t- waiting on " + t.getLockInfo()); out.print('\n'); break; default: } } for (MonitorInfo mi : lockedMonitors) { if (mi.getLockedStackDepth() == i) { out.print("\t- locked " + mi); out.print('\n'); } } } LockInfo[] locks = t.getLockedSynchronizers(); if (locks.length > 0) { out.print("\n\tNumber of locked synchronizers = " + locks.length); out.print('\n'); for (LockInfo li : locks) { out.print("\t- " + li); out.print('\n'); } } out.print('\n'); }
Example 19
Source File: SampledCPUSnapshot.java From netbeans with Apache License 2.0 | 4 votes |
private void print16Thread(final StringBuilder sb, final ThreadInfo thread, boolean goToSourceAvailable) { MonitorInfo[] monitors = thread.getLockedMonitors(); sb.append(" <b>"); // NOI18N sb.append("\"").append(thread.getThreadName()).append("\" - Thread t@").append(thread.getThreadId()).append("<br>"); // NOI18N sb.append(" java.lang.Thread.State: ").append(thread.getThreadState()); // NOI18N sb.append("</b><br>"); // NOI18N int index = 0; for (StackTraceElement st : thread.getStackTrace()) { LockInfo lock = thread.getLockInfo(); String stackElementText = htmlize(st.toString()); String lockOwner = thread.getLockOwnerName(); String className = st.getClassName(); String method = st.getMethodName(); int lineNo = st.getLineNumber(); String stackEl = stackElementText; if (goToSourceAvailable) { String stackUrl = OPEN_THREADS_URL+className+"|"+method+"|"+lineNo; // NOI18N stackEl = "<a href=\""+stackUrl+"\">"+stackElementText+"</a>"; // NOI18N } sb.append("\tat ").append(stackEl).append("<br>"); // 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("<br>"); // NOI18N } } else if (lock != null) { if (lockOwner == null) { sb.append("\t- parking to wait for "); // NOI18N printLock(sb,lock); sb.append("<br>"); // NOI18N } else { sb.append("\t- waiting to lock "); // NOI18N printLock(sb,lock); sb.append(" owned by \"").append(lockOwner).append("\" t@").append(thread.getLockOwnerId()).append("<br>"); // NOI18N } } } printMonitors(sb, monitors, index); index++; } StringBuilder jnisb = new StringBuilder(); printMonitors(jnisb, monitors, -1); if (jnisb.length() > 0) { sb.append(" JNI locked monitors:<br>"); sb.append(jnisb); } LockInfo[] synchronizers = thread.getLockedSynchronizers(); if (synchronizers != null) { sb.append("<br> Locked ownable synchronizers:"); // NOI18N if (synchronizers.length == 0) { sb.append("<br>\t- None\n"); // NOI18N } else { for (LockInfo li : synchronizers) { sb.append("<br>\t- locked "); // NOI18N printLock(sb,li); sb.append("<br>"); // NOI18N } } } sb.append("<br>"); }
Example 20
Source File: ThreadMXBeanStateTest.java From openjdk-jdk9 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()); } }