Java Code Examples for java.lang.management.ThreadInfo#getThreadName()

The following examples show how to use java.lang.management.ThreadInfo#getThreadName() . 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: ThreadMonitor.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 2
Source File: Diagnostics.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Formats the thread dump header for one thread.
 *
 * @param ti the ThreadInfo describing the thread
 * @return the formatted thread dump header
 */
private static String getThreadDumpHeader(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"");
    sb.append(" Id=" + ti.getThreadId());
    sb.append(" cpu=" + threadMXBean.getThreadCpuTime(ti.getThreadId()) +
              " ns");
    sb.append(" usr=" + threadMXBean.getThreadUserTime(ti.getThreadId()) +
              " ns");
    sb.append(" blocked " + ti.getBlockedCount() + " for " +
              ti.getBlockedTime() + " ms");
    sb.append(" waited " + ti.getWaitedCount() + " for " +
              ti.getWaitedTime() + " ms");

    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (running in native)");
    }
    sb.append(CRLF);
    sb.append(INDENT3 + "java.lang.Thread.State: " + ti.getThreadState());
    sb.append(CRLF);
    return sb.toString();
}
 
Example 3
Source File: ThreadMonitor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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: ThreadMonitor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 6
Source File: Basic.java    From streamsupport with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A debugging tool to print stack traces of most threads, as jstack does.
 * Uninteresting threads are filtered out.
 */
static void dumpTestThreads() {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    System.err.println("------ stacktrace dump start ------");
    for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
        String name = info.getThreadName();
        if ("Signal Dispatcher".equals(name))
            continue;
        if ("Reference Handler".equals(name)
            && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
            continue;
        if ("Finalizer".equals(name)
            && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
            continue;
        if ("process reaper".equals(name))
            continue;
        if (name != null && name.startsWith("ForkJoinPool.commonPool-worker"))
            continue;
        System.err.print(info);
    }
    System.err.println("------ stacktrace dump end ------");
}
 
Example 7
Source File: ThreadMonitor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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: Diagnostics.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Formats the thread dump header for one thread.
 *
 * @param ti the ThreadInfo describing the thread
 * @return the formatted thread dump header
 */
private static String getThreadDumpHeader(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"");
    sb.append(" Id=" + ti.getThreadId());
    sb.append(" cpu=" + threadMXBean.getThreadCpuTime(ti.getThreadId()) +
              " ns");
    sb.append(" usr=" + threadMXBean.getThreadUserTime(ti.getThreadId()) +
              " ns");
    sb.append(" blocked " + ti.getBlockedCount() + " for " +
              ti.getBlockedTime() + " ms");
    sb.append(" waited " + ti.getWaitedCount() + " for " +
              ti.getWaitedTime() + " ms");

    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (running in native)");
    }
    sb.append(CRLF);
    sb.append(INDENT3 + "java.lang.Thread.State: " + ti.getThreadState());
    sb.append(CRLF);
    return sb.toString();
}
 
Example 9
Source File: Basic.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A debugging tool to print stack traces of most threads, as jstack does.
 * Uninteresting threads are filtered out.
 */
static void dumpTestThreads() {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    System.err.println("------ stacktrace dump start ------");
    for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
        String name = info.getThreadName();
        if ("Signal Dispatcher".equals(name))
            continue;
        if ("Reference Handler".equals(name)
            && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
            continue;
        if ("Finalizer".equals(name)
            && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
            continue;
        if ("process reaper".equals(name))
            continue;
        if (name != null && name.startsWith("ForkJoinPool.commonPool-worker"))
            continue;
        System.err.print(info);
    }
    System.err.println("------ stacktrace dump end ------");
}
 
Example 10
Source File: ThreadingManager.java    From vi with Apache License 2.0 6 votes vote down vote up
public static List<TInfo> getAllThreadInfo(){

        List<TInfo> threads = new ArrayList<>();
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        long[] ids = threadBean.getAllThreadIds();
        ThreadInfo[] infos = threadBean.getThreadInfo(ids);
        for (ThreadInfo info : infos){
            long id = info.getThreadId();
            TInfo tInfo = new TInfo();
            tInfo.name = info.getThreadName();
            tInfo.id = id;
            tInfo.state = info.getThreadState();
            tInfo.cpuTime = threadBean.getThreadCpuTime(id);
            threads.add(tInfo);
        }
        Collections.sort(threads,new Comparator<TInfo>() {
            @Override
            public int compare(TInfo o1, TInfo o2) {
                return Long.compare(o2.cpuTime,o1.cpuTime);
            }
        });
        return threads;
    }
 
Example 11
Source File: ThreadInfoTask.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
private List<ThreadBrief> getAllThreadsInfo(VirtualMachineUtil.VMConnector connect, Map<String, Object> result) {
    List<ThreadBrief> threads = new ArrayList<>();
    long totalCpuTime = 0;
    try {
        ThreadMXBean threadMXBean = connect.getThreadMXBean();
        long[] ids = threadMXBean.getAllThreadIds();
        ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(ids);
        for (ThreadInfo info : threadInfos) {
            long thId = info.getThreadId();
            long cpuTime = threadMXBean.getThreadCpuTime(thId);
            ThreadBrief threadBrief = new ThreadBrief(info.getThreadId(), info.getThreadName(),
                    cpuTime, info.getThreadState());
            totalCpuTime += cpuTime;
            threads.add(threadBrief);
        }
        Collections.sort(threads, new Comparator<ThreadBrief>() {
            @Override
            public int compare(ThreadBrief o1, ThreadBrief o2) {
                return Long.compare(o2.cpuTime, o1.cpuTime);
            }
        });
        result.put("totalCpuTime", totalCpuTime);
        return threads;
    } catch (IOException e) {
        logger.error("get all thread info error", e);
        return threads;
    }
}
 
Example 12
Source File: LongGCDisruption.java    From crate with Apache License 2.0 5 votes vote down vote up
protected void onBlockDetected(ThreadInfo blockedThread, @Nullable ThreadInfo blockingThread) {
    String blockedThreadStackTrace = stackTrace(blockedThread.getStackTrace());
    String blockingThreadStackTrace = blockingThread != null ?
        stackTrace(blockingThread.getStackTrace()) : "not available";
    throw new AssertionError("Thread [" + blockedThread.getThreadName() + "] is blocked waiting on the resource [" +
        blockedThread.getLockInfo() + "] held by the suspended thread [" + blockedThread.getLockOwnerName() +
        "] of the disrupted node [" + disruptedNode + "].\n" +
        "Please add this occurrence to the unsafeClasses list in [" + LongGCDisruption.class.getName() + "].\n" +
        "Stack trace of blocked thread: " + blockedThreadStackTrace + "\n" +
        "Stack trace of blocking thread: " + blockingThreadStackTrace);
}
 
Example 13
Source File: Sampler.java    From spark with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    for (ThreadInfo threadInfo : this.threadDumps) {
        if (threadInfo.getThreadName() == null || threadInfo.getStackTrace() == null) {
            continue;
        }
        this.dataAggregator.insertData(threadInfo);
    }
}
 
Example 14
Source File: Detector.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Use exception reporter to report the stack trace of the deadlocked threads.
 * @param deadlocked 
 */
private void reportStackTrace(ThreadInfo[] deadlocked, File report) {
    DeadlockDetectedException deadlockException = new DeadlockDetectedException(null);
    deadlockException.setStackTrace(deadlocked[0].getStackTrace());
    DeadlockDetectedException lastDde = deadlockException;
    for (ThreadInfo toBeReported : deadlocked) {
        DeadlockDetectedException dde = new DeadlockDetectedException(toBeReported.getThreadName());
        dde.setStackTrace(toBeReported.getStackTrace());
        lastDde.initCause(dde);
        lastDde = dde;
    }
    LOG.log(Level.SEVERE, report.getAbsolutePath(), deadlockException);
}
 
Example 15
Source File: AEThreadMonitor.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
private void
dumpThreads(
	IndentWriter		writer )
{
	final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

	long[] allThreadIds = threadBean.getAllThreadIds();
	writer.println("Threads " + allThreadIds.length);
	writer.indent();

	List<ThreadInfo> threadInfos = new ArrayList<>(allThreadIds.length);
	for (int i = 0; i < allThreadIds.length; i++) {
		ThreadInfo info = threadBean.getThreadInfo(allThreadIds[i], 32);
		if(info != null)
			threadInfos.add(info);
	}

	Collections.sort(threadInfos, new Comparator<ThreadInfo>() {
		@Override
		public int compare(ThreadInfo o1, ThreadInfo o2) {

			long diff = threadBean.getThreadCpuTime(o2.getThreadId())
					- threadBean.getThreadCpuTime(o1.getThreadId());
			if (diff == 0) {
				return o1.getThreadName().compareToIgnoreCase(o2.getThreadName());
			}
			return diff > 0 ? 1 : -1;
		}
	});

	for (int i = 0; i < threadInfos.size(); i++) {
		try {
			ThreadInfo threadInfo = threadInfos.get(i);

			long lCpuTime = threadBean.getThreadCpuTime(threadInfo.getThreadId());
			if (lCpuTime == 0)
				break;

			String sState;
			switch (threadInfo.getThreadState()) {
				case BLOCKED:
					sState = "Blocked";
					break;
				case RUNNABLE:
					sState = "Runnable";
					break;
				case NEW:
					sState = "New";
					break;
				case TERMINATED:
					sState = "Terminated";
					break;
				case TIMED_WAITING:
					sState = "Timed Waiting";
					break;

				case WAITING:
					sState = "Waiting";
					break;

				default:
					sState = "" + threadInfo.getThreadState();
					break;

			}

			String sName = threadInfo.getThreadName();
			String sLockName = threadInfo.getLockName();

			writer.println(sName
					+ ": "
					+ sState
					+ ", "
					+ (lCpuTime / 1000000)
					+ "ms CPU, "
					+ "B/W: "
					+ threadInfo.getBlockedCount()
					+ "/"
					+ threadInfo.getWaitedCount()
					+ (sLockName == null ? "" : "; Locked by " + sLockName + "/"
							+ threadInfo.getLockOwnerName()));

			writer.indent();
			try {
				StackTraceElement[] stackTrace = threadInfo.getStackTrace();
				for (int j = 0; j < stackTrace.length; j++) {
					writer.println(stackTrace[j].toString());
				}
			} finally {
				writer.exdent();
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	writer.exdent();
}
 
Example 16
Source File: DeadlockMonitorTask.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
/**
 * 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 17
Source File: ThreadMXBeanDataManager.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void fillInThreadData() {
    long[] currentThreadIds = threadBean.getAllThreadIds();
    ThreadInfo[] threadInfos = threadBean.getThreadInfo(currentThreadIds, 1);
    Set<Long> currentIdSet = new HashSet(currentThreadIds.length * 4 / 3);
    int nThreads = 0;
    long timeStamps[] = {System.currentTimeMillis()};
    int maxThreads = currentThreadIds.length + threadIdSet.size();
    int tids[] = new int[maxThreads];
    byte states[] = new byte[maxThreads];

    int nNewThreads = 0;
    int newThreadsId[] = new int[currentThreadIds.length];
    String[] newThreadsNames = new String[currentThreadIds.length];
    String[] newThreadsClasses = new String[currentThreadIds.length];

    for (int i = 0; i < currentThreadIds.length; i++) {
        ThreadInfo tinfo = threadInfos[i];
        long threadId = currentThreadIds[i];
        Long threadIdLong;

        if (tinfo == null) {
            continue;
        }
        threadIdLong = Long.valueOf(threadId);
        currentIdSet.add(threadIdLong);
        tids[nThreads] = (int) threadId;
        states[nThreads] = getState(tinfo);
        nThreads++;

        if (!threadIdSet.remove(threadIdLong)) { // New Thread
            newThreadsId[nNewThreads] = (int) threadId;
            newThreadsNames[nNewThreads] = tinfo.getThreadName();
            newThreadsClasses[nNewThreads] = "";
            nNewThreads++;
        }
    }
    // set remaining threads as terminated
    for (Iterator it = threadIdSet.iterator(); it.hasNext();) {
        Long elem = (Long) it.next();
        tids[nThreads] = elem.intValue();
        states[nThreads] = CommonConstants.THREAD_STATUS_ZOMBIE;
        nThreads++;
    }
    threadIdSet = currentIdSet;
    setDataOnNewThreads(nNewThreads, newThreadsId, newThreadsNames, newThreadsClasses);
    setDataOnThreads(nThreads, timeStamps.length, tids, timeStamps, states);
}
 
Example 18
Source File: ThreadInfoCompositeData.java    From native-obfuscator with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: ThreadDumpUtil.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
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 20
Source File: ThreadInfoCompositeData.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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());
}