Java 8 ThreadInfo - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ThreadInfo class.

This code example shows how to use the following methods:getLockName, getLockOwnerId, getLockOwnerName, getThreadId, getThreadName
out.println();
  } 
 
  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());

7
CodeRank
This code example shows how to use the following methods:getLockName, getLockOwnerId, getLockOwnerName, getThreadId, getThreadName
out.println();
  } 
 
  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());

7
CodeRank
This code example shows how to use the following methods:getLockName, getLockOwnerId, getLockOwnerName, getThreadId, getThreadName
      threadDump.append("\n");
   } 
 
   private static void printThread(ThreadInfo threadInfo, StringBuilder threadDump) {
      StringBuilder sb = new StringBuilder(
            "\"" + threadInfo.getThreadName() + "\"" +
            " nid=" + threadInfo.getThreadId() + " state=" +
            threadInfo.getThreadState());
      if (threadInfo.getLockName() != null && threadInfo.getThreadState() != Thread.State.BLOCKED) {
          String[] lockInfo = threadInfo.getLockName().split("@");
          sb.append("\n" + INDENT +"- waiting on <0x" + lockInfo[1] + "> (a " + lockInfo[0] + ")");
          sb.append("\n" + INDENT +"- locked <0x" + lockInfo[1] + "> (a " + lockInfo[0] + ")");
      } else if (threadInfo.getLockName() != null && threadInfo.getThreadState() == Thread.State.BLOCKED) {
          String[] lockInfo = threadInfo.getLockName().split("@");
          sb.append("\n" + INDENT +"- waiting to lock <0x" + lockInfo[1] + "> (a " + lockInfo[0] + ")");
      } 
      if (threadInfo.isSuspended())
          sb.append(" (suspended)");
 
      if (threadInfo.isInNative())

6
CodeRank
This code example shows how to use the following methods:getBlockedCount, getBlockedTime, getWaitedCount, getWaitedTime
  public void monitorStarted(Monitor monitor) {
    if (enabled && monitor instanceof  TransactionMonitor) {
      ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();
      long id = Thread.currentThread().getId();
      ThreadInfo threadInfo = tmxbean.getThreadInfo(id);
      monitor.set("startBlockedCount", threadInfo.getBlockedCount());
      monitor.set("startBlockedTime", threadInfo.getBlockedTime());
      monitor.set("startWaitedCount", threadInfo.getWaitedCount());
      monitor.set("startWaitedTime", threadInfo.getWaitedTime());
    } 
  } 
 
  public void process(Monitor monitor) {
    if (enabled && monitor instanceof  TransactionMonitor) {
      if (monitor.hasAttribute("startBlockedCount") 
          && monitor.hasAttribute("startBlockedCount") 
          && monitor.hasAttribute("startBlockedCount") 
          && monitor.hasAttribute("startBlockedCount")) {
        TransactionMonitor tMon = (TransactionMonitor) monitor;
        ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();      
6
CodeRank
This code example shows how to use the following methods:getLockOwnerId, getThreadId
        if (node == null)
        { 
            return; 
        } 
 
        String threadInfoStr = WaitMonitor.toString(threadInfo.getThreadId(), threadInfo);
        node.setLoggingValue(KEY_THREAD_MONITOR_THREAD, threadInfoStr);
        long lockOwnerId = threadInfo.getLockOwnerId();
        if (lockOwnerId == 0)
        { 
            return; 
        } 
 
        ThreadInfo lockOwnerThreadInfo = ThreadUtil.getThreadInfo(lockOwnerId, maxDepth);
        if (lockOwnerThreadInfo != null)
        { 
            String lockOwnerThreadInfoStr = WaitMonitor.toString(lockOwnerId, lockOwnerThreadInfo);
            node.setLoggingValue(KEY_THREAD_MONITOR_OWNER, lockOwnerThreadInfoStr);
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:getLockInfo, getLockOwnerName, getThreadName
    } 
 
    protected void printDeadlockedThreadInfo(ThreadWriter threadWriter, ThreadInfo info)
    { 
        threadWriter.println("\"{0}\":", new Object[]
            { info.getThreadName() }); 
        threadWriter.println("  waiting to lock monitor {0} (object {1}, a {2}),", new Object[]
            { "7f8a5595d180" /* ? */, Integer.toHexString(info.getLockInfo().getIdentityHashCode()), 
                info.getLockInfo().getClassName() }); 
        threadWriter.println("  which is held by \"{0}\"", new Object[]
            { info.getLockOwnerName() }); 
    } 
 
    private static void printLockInfo(ThreadWriter threadWriter, String pattern, LockInfo lockInfo)
    { 
        printLockInfo(threadWriter, pattern, lockInfo, null, -1);
    } 
 
    private static void printLockInfo(ThreadWriter threadWriter, String pattern, LockInfo lockInfo,
        String lockOwnerName, long lockOwnerId)
6
CodeRank
This code example shows how to use the following methods:getLockName, getLockOwnerId, getLockOwnerName, getThreadId, getThreadName
System.out.println();
    } 
 
    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() +

6
CodeRank
This code example shows how to use the following methods:getBlockedCount, getBlockedTime, getThreadId, getThreadName, getThreadState
     * 
     * @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()) {

5
CodeRank
This code example shows how to use the following methods:getWaitedCount, getWaitedTime
     * @param threadInfo 現在のスレッド情報。 
     * @return waitが継続しているかどうか。 
     */ 
    public boolean isTarget(final ThreadInfo prevThreadInfo, final ThreadInfo threadInfo)
    { 
        return threadInfo != null && threadInfo.getWaitedCount() == prevThreadInfo.getWaitedCount()
                && threadInfo.getWaitedTime() != prevThreadInfo.getWaitedTime();
    } 
 
    /** 
     * 指定したnodeにwaitの状況を追加する。 
     *  
     * @param node 対象のCallTreeNode。 
     * @param threadInfo 現在のスレッド情報。 
     * @param prevThreadInfo 前回のスレッド情報。 
     * @param maxDepth 取得するスタックトレースの深さ。 
     */ 
    public void updateNode(final CallTreeNode node, final ThreadInfo threadInfo,
            final ThreadInfo prevThreadInfo, final int maxDepth)
    { 
5
CodeRank
This code example shows how to use the following methods:getLockedMonitors, getLockedSynchronizers, getStackTrace, getThreadId, getThreadName
 
    @Before 
    public void setUp() throws Exception {
        final StackTraceElement rLine1 = new StackTraceElement("Blah", "blee", "Blah.java", 100);
 
        when(runnable.getThreadName()).thenReturn("runnable");
        when(runnable.getThreadId()).thenReturn(100L);
        when(runnable.getThreadState()).thenReturn(Thread.State.RUNNABLE);
        when(runnable.getStackTrace()).thenReturn(new StackTraceElement[]{ rLine1 });
        when(runnable.getLockedMonitors()).thenReturn(new MonitorInfo[]{ });
        when(runnable.getLockedSynchronizers()).thenReturn(new LockInfo[]{ });
 
        when(threadMXBean.dumpAllThreads(true, true)).thenReturn(new ThreadInfo[]{
                runnable
        }); 
    } 
 
    @Test
    public void dumpsAllThreads() throws Exception {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
5
CodeRank
See Code Examples for Java 8 ThreadInfo Methods: