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

The following examples show how to use java.lang.management.ThreadInfo#getThreadId() . 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 jdk8u60 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: ResponsivenessMonitor.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Log detail about UI freezeup */
private void reportUIFreeze()
{
    final StringBuilder buf = new StringBuilder();
    buf.append("UI Freezeup\n\n");
    final ThreadInfo[] thread_infos = thread_bean.dumpAllThreads(dumpLockedMonitors, dumpLockedSynchronizers);
    for (ThreadInfo info : thread_infos)
    {
        if (info.getThreadId() == Thread.currentThread().getId())
        {
            // Exclude the ResponsivenessMonitor thread
            continue;
        }
        if (info.getThreadId() == ui_thread_id)
        {
            buf.append("\n");
            buf.append("*********************************\n");
            buf.append("*** JavaFX Application Thread ***\n");
            buf.append("*********************************\n");
        }
        buf.append(info);
    }

    logger.log(Level.SEVERE, buf.toString());
}
 
Example 3
Source File: ManagementFactoryTest.java    From banyan with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    List<GarbageCollectorMXBean> garbageCollectorMXBeanList = ManagementFactory.getGarbageCollectorMXBeans();

    for (GarbageCollectorMXBean gcMXBean : garbageCollectorMXBeanList) {
        String gcName = gcMXBean.getName();
        String memoryPoolNames[] = gcMXBean.getMemoryPoolNames();
        for (String memoryPoolName : memoryPoolNames) {
            System.out.println(memoryPoolName);
        }
        ObjectName objectName = gcMXBean.getObjectName();
        String domainName = objectName.getDomain();
        System.out.println(domainName+"__"+objectName.getCanonicalName());
        System.out.println(gcName);

    }

    //不需要获取同步的monitor 和 synchronize信息,仅获取线程和线程堆栈信息。
    ThreadInfo[] allThreads = threadMXBean.dumpAllThreads(true, true);
    for (ThreadInfo threadInfo : allThreads) {
        String threadName = threadInfo.getThreadName();
        long threadId = threadInfo.getThreadId();
        System.out.println(threadName + "," + threadId + "," + threadInfo.getLockOwnerName());
    }
}
 
Example 4
Source File: ThreadMonitor.java    From openjdk-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 5
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 6
Source File: ThreadsIterator.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public Object next() {
  ThreadInfo currentThread = threadInfoIterator.next();
  final NodeEndpoint endpoint = dbContext.getEndpoint();
  final long id = currentThread.getThreadId();
  return new ThreadSummary(endpoint.getAddress(),
          endpoint.getFabricPort(),
          currentThread.getThreadName(),
          currentThread.getThreadId(),
          currentThread.isInNative(),
          currentThread.isSuspended(),
          currentThread.getThreadState().name(),
          stats.getCpuTrailingAverage(id, 1),
          stats.getUserTrailingAverage(id, 1),
          VM.availableProcessors(),
          getStackTrace(currentThread));
}
 
Example 7
Source File: ThreadMonitor.java    From openjdk-jdk8u-backup 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: 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 9
Source File: CrossedStealingDeadlockIT.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
private static String dumpThread(ThreadInfo thread) {
  StringBuilder sb = new StringBuilder("\"" + thread.getThreadName() + "\"" +
                                       " Id=" + thread.getThreadId() + " " +
                                       thread.getThreadState());
  if (thread.getLockName() != null) {
      sb.append(" on " + thread.getLockName());
  }
  if (thread.getLockOwnerName() != null) {
      sb.append(" owned by \"" + thread.getLockOwnerName() +
                "\" Id=" + thread.getLockOwnerId());
  }
  if (thread.isSuspended()) {
      sb.append(" (suspended)");
  }
  if (thread.isInNative()) {
      sb.append(" (in native)");
  }
  sb.append('\n');

  StackTraceElement[] trace = thread.getStackTrace();
  for (StackTraceElement ste : trace) {
    sb.append("\tat " + ste.toString());
    sb.append('\n');
  }
  sb.append('\n');
  return sb.toString();
}
 
Example 10
Source File: ThreadMXBeanExample.java    From banyan with MIT License 5 votes vote down vote up
public static void main(String... args) {
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
        for (ThreadInfo threadInfo : threadInfos) {
            long threadId = threadInfo.getThreadId();
            String threadName = threadInfo.getThreadName();
            Thread.State state = threadInfo.getThreadState();
            System.out.println(threadInfo.toString());
//            System.out.println("Thread id:" + threadId + " ;Thread name:" + threadName + "; Thread state:" + state.name());
        }

    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: SdcInfoContentGenerator.java    From datacollector with Apache License 2.0 4 votes vote down vote up
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 13
Source File: ThreadInfoCompositeData.java    From dragonwell8_jdk 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());
}
 
Example 14
Source File: LocalThread.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public LocalThread(Serializable locatility, ThreadInfo info) {
  this.locality = locatility;
  this.threadName = info.getThreadName();
  this.threadStack = generateThreadStack(info);
  this.threadId = info.getThreadId();
}
 
Example 15
Source File: ThreadInfoCompositeData.java    From jdk8u60 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());
}
 
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: JVMUtil.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
private static String getThreadDumpString(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;

    StackTraceElement[] stackTrace = threadInfo.getStackTrace();
    MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
    for (; i < stackTrace.length && i < 32; i++) {
        StackTraceElement ste = stackTrace[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 : lockedMonitors) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    if (i < stackTrace.length) {
        sb.append("\t...");
        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 18
Source File: ThreadInfoCompositeData.java    From jdk8u_jdk 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());
}
 
Example 19
Source File: ThreadInfoCompositeData.java    From openjdk-jdk9 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]);
    }
    if (!values[DAEMON].equals(info.isDaemon())) {
        throw new RuntimeException("Daemon = " +
           info.isDaemon() + " expected = " +
           values[DAEMON]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
Example 20
Source File: JMServer.java    From jmonitor with GNU General Public License v2.0 4 votes vote down vote up
@HttpMapping(url = "/loadThreadInfo")
public JSONObject doLoadThreadInfo(Map<String, Object> param) {
    try {
        String app = ((HttpServletRequest) param.get(JMDispatcher.REQ)).getParameter("app");
        ThreadMXBean tBean = JMConnManager.getThreadMBean(app);
        ThreadInfo[] allThreads = tBean.dumpAllThreads(false, false);

        JSONObject root = new JSONObject();
        JSONArray detail = new JSONArray();
        HashMap<State, Integer> state = new HashMap<Thread.State, Integer>();
        for (ThreadInfo info : allThreads) {
            JSONObject th = new JSONObject();
            long threadId = info.getThreadId();
            long cpu = tBean.getThreadCpuTime(threadId);
            State tState = info.getThreadState();

            th.put("id", threadId);
            th.put("state", tState);
            th.put("name", info.getThreadName());
            th.put("cpu", TimeUnit.NANOSECONDS.toMillis(cpu));
            detail.add(th);

            Integer vl = state.get(tState);
            if (vl == null) {
                state.put(tState, 0);
            } else {
                state.put(tState, vl + 1);
            }
        }

        root.put("state", state);
        root.put("detail", detail);
        root.put("total", tBean.getThreadCount());
        root.put("time", System.currentTimeMillis());
        root.put("deamon", tBean.getDaemonThreadCount());

        return root;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}