当前位置: 首页>>代码示例>>Java>>正文


Java ThreadInfo.getThreadState方法代码示例

本文整理汇总了Java中java.lang.management.ThreadInfo.getThreadState方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadInfo.getThreadState方法的具体用法?Java ThreadInfo.getThreadState怎么用?Java ThreadInfo.getThreadState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ThreadInfo的用法示例。


在下文中一共展示了ThreadInfo.getThreadState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void printThread(ThreadInfo ti, PrintStream out) {
   StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + // NOI18N
                                        " Id=" + ti.getThreadId() +       // NOI18N
                                        " in " + ti.getThreadState());    // NOI18N
   if (ti.getLockName() != null) {
       sb.append(" on lock=").append(ti.getLockName()); // NOI18N
   }
   if (ti.isSuspended()) {
       sb.append(" (suspended)"); // NOI18N
   }
   if (ti.isInNative()) {
       sb.append(" (running in native)"); // NOI18N
   }
   out.println(sb.toString());
   if (ti.getLockOwnerName() != null) {
        out.println(INDENT + " owned by " + ti.getLockOwnerName() + // NOI18N
                           " Id=" + ti.getLockOwnerId());           // NOI18N
   }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Detector.java

示例2: getThreadUsage

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void getThreadUsage(MetricsRecordBuilder rb) {
  int threadsNew = 0;
  int threadsRunnable = 0;
  int threadsBlocked = 0;
  int threadsWaiting = 0;
  int threadsTimedWaiting = 0;
  int threadsTerminated = 0;
  long threadIds[] = threadMXBean.getAllThreadIds();
  for (ThreadInfo threadInfo : threadMXBean.getThreadInfo(threadIds, 0)) {
    if (threadInfo == null) continue; // race protection
    switch (threadInfo.getThreadState()) {
      case NEW:           threadsNew++;           break;
      case RUNNABLE:      threadsRunnable++;      break;
      case BLOCKED:       threadsBlocked++;       break;
      case WAITING:       threadsWaiting++;       break;
      case TIMED_WAITING: threadsTimedWaiting++;  break;
      case TERMINATED:    threadsTerminated++;    break;
    }
  }
  rb.addGauge(ThreadsNew, threadsNew)
    .addGauge(ThreadsRunnable, threadsRunnable)
    .addGauge(ThreadsBlocked, threadsBlocked)
    .addGauge(ThreadsWaiting, threadsWaiting)
    .addGauge(ThreadsTimedWaiting, threadsTimedWaiting)
    .addGauge(ThreadsTerminated, threadsTerminated);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:27,代码来源:JvmMetrics.java

示例3: getState

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public static Byte[] getState(ThreadInfo info) {
    byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
    try {
        final Thread.State state = info.getThreadState();
        final boolean inNative  = info.isInNative();
        final boolean suspended = info.isSuspended();
        log.debug("getJvmThreadInstState",
                  "[State=" + state +
                  ",isInNative=" + inNative +
                  ",isSuspended=" + suspended + "]");
        setState(bitmap,state);
        if (inNative)  setNative(bitmap);
        if (suspended) setSuspended(bitmap);
        checkOther(bitmap);
    } catch (RuntimeException r) {
        bitmap[0]=(byte)0x00;
        bitmap[1]=Byte1.other;
        log.trace("getJvmThreadInstState",
                  "Unexpected exception: " + r);
        log.debug("getJvmThreadInstState",r);
    }
    Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
    return result;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:JvmThreadInstanceEntryImpl.java

示例4: checkSuspendedThreadState

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void checkSuspendedThreadState(ThreadStateController t, Thread.State state) {
    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 (!info.isSuspended()) {
        throw new RuntimeException(t.getName() + " expected to be suspended " +
            " but isSuspended() returns " + info.isSuspended());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ThreadMXBeanStateTest.java

示例5: calculateCycleDeadlockChains

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private Set<LinkedHashSet<ThreadInfo>> calculateCycleDeadlockChains(ImmutableMap<Long, ThreadInfo> threadInfoMap, Set<LinkedHashSet<ThreadInfo>> cycles) {
    ThreadInfo allThreads[] = threadBean.getThreadInfo(threadBean.getAllThreadIds());
    Set<LinkedHashSet<ThreadInfo>> deadlockChain = new HashSet<>();
    Set<Long> knownDeadlockedThreads = threadInfoMap.keySet();
    for (ThreadInfo threadInfo : allThreads) {
        Thread.State state = threadInfo.getThreadState();
        if (state == Thread.State.BLOCKED && !knownDeadlockedThreads.contains(threadInfo.getThreadId())) {
            for (LinkedHashSet cycle : cycles) {
                if (cycle.contains(threadInfoMap.get(Long.valueOf(threadInfo.getLockOwnerId())))) {
                    LinkedHashSet<ThreadInfo> chain = new LinkedHashSet<>();
                    for (ThreadInfo node = threadInfo; !chain.contains(node); node = threadInfoMap.get(Long.valueOf(node.getLockOwnerId())))
                        chain.add(node);

                    deadlockChain.add(chain);
                }
            }

        }
    }

    return deadlockChain;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:DeadlockAnalyzer.java

示例6: printThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
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());
   }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ThreadMonitor.java

示例7: printThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public static void printThreadInfo(PrintWriter stream, String title) {
  int STACK_DEPTH = 20;
  boolean contention = threadBean.isThreadContentionMonitoringEnabled();
  long[] threadIds = threadBean.getAllThreadIds();
  stream.println("Process Thread Dump: " + title);
  stream.println(threadIds.length + " active threads");
  for (long tid : threadIds) {
    ThreadInfo info = threadBean.getThreadInfo(tid, 20);
    if (info == null) {
      stream.println("  Inactive");
    } else {
      stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":");

      Thread.State state = info.getThreadState();
      stream.println("  State: " + state);
      stream.println("  Blocked count: " + info.getBlockedCount());
      stream.println("  Waited count: " + info.getWaitedCount());
      if (contention) {
        stream.println("  Blocked time: " + info.getBlockedTime());
        stream.println("  Waited time: " + info.getWaitedTime());
      }
      if (state == Thread.State.WAITING) {
        stream.println("  Waiting on " + info.getLockName());
      } else if (state == Thread.State.BLOCKED) {
        stream.println("  Blocked on " + info.getLockName());
        stream.println("  Blocked by "
            + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
      }

      stream.println("  Stack:");
      for (StackTraceElement frame : info.getStackTrace())
        stream.println("    " + frame.toString());
    }
  }
  stream.flush();
}
 
开发者ID:Tencent,项目名称:angel,代码行数:37,代码来源:ReflectionUtils.java

示例8: waitUntilBlockingOnObject

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Waits until {@link Thread} is in the certain {@link Thread.State}
 * and blocking on {@code object}.
 *
 * @param state The thread state
 * @param object The object to block on
 */
public static void waitUntilBlockingOnObject(Thread thread, Thread.State state, Object object)
    throws InterruptedException {
    String want = object == null ? null : object.getClass().getName() + '@'
            + Integer.toHexString(System.identityHashCode(object));
    ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
    while (thread.isAlive()) {
        ThreadInfo ti = tmx.getThreadInfo(thread.getId());
        if (ti.getThreadState() == state
                && (want == null || want.equals(ti.getLockName()))) {
            return;
        }
        Thread.sleep(1);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ThreadMXBeanTool.java

示例9: dumpThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void dumpThread(ThreadInfo thread, Logger log, Level level)
{
    if (thread == null) return;
    if ( thread.getThreadState() != State.WAITING )
    {
        log.log( level, "------------------------------" );
        //
        log.log( level, "Current Thread: " + thread.getThreadName() );
        log.log( level, "\tPID: " + thread.getThreadId()
                + " | Suspended: " + thread.isSuspended()
                + " | Native: " + thread.isInNative()
                + " | State: " + thread.getThreadState() 
                + " | Blocked Time: " + thread.getBlockedTime()     // Cauldron add info about blocked time
                + " | Blocked Count: " + thread.getBlockedCount()); // Cauldron add info about blocked count
        
        if ( thread.getLockedMonitors().length != 0 )
        {
            log.log( level, "\tThread is waiting on monitor(s):" );
            for ( MonitorInfo monitor : thread.getLockedMonitors() )
            {
                log.log( level, "\t\tLocked on:" + monitor.getLockedStackFrame() );
            }
        }
        if ( thread.getLockOwnerId() != -1 ) log.log( level, "\tLock Owner Id: " + thread.getLockOwnerId()); // Cauldron + add info about lock owner thread id
        log.log( level, "\tStack:" );
        //
        StackTraceElement[] stack = thread.getStackTrace();
        for ( int line = 0; line < stack.length; line++ )
        {
            log.log( level, "\t\t" + stack[line].toString() );
        }
    }
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:34,代码来源:WatchdogThread.java

示例10: getThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static ThreadInfo getThreadInfo(ThreadStateController t, Thread.State expected) {
    // wait for the thread to transition to the expected state.
    // There is a small window between the thread checking the state
    // and the thread actual entering that state.
    int retryCount=0;
    ThreadInfo info = tm.getThreadInfo(t.getId());
    while (info.getThreadState() != expected && retryCount < MAX_RETRY) {
        ThreadStateController.pause(10);
        retryCount++;
        info = tm.getThreadInfo(t.getId());
    }
    return info;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ThreadMXBeanStateTest.java

示例11: getThreadDebugData

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/** Returns an array list of debug information for all Java threads; useful for trying to diagnose the cause of odd behaviour.
 * 
 * @return An array list of debug information
 */
public static ArrayList<String> getThreadDebugData()
{
	ArrayList<String> strings = new ArrayList<String>();

	strings.add("------------------------------------------------------------");
	strings.add("Debugging information for Java virtual machine");
	ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
	for (ThreadInfo thread : threads)
	{
		if (thread.getThreadState() != State.WAITING)
		{
			strings.add("------------------------------------------------------------");
			strings.add(thread.getThreadName());
			strings.add("\tPID: " + thread.getThreadId() + " | Suspended: " + thread.isSuspended() + " | Native: " + thread.isInNative() + " | State: " + thread.getThreadState());
			if (thread.getLockedMonitors().length != 0)
			{
				strings.add("\tThread is waiting on monitor(s):");
				for (MonitorInfo monitor : thread.getLockedMonitors())
				{
					strings.add("\t\tLocked on:" + monitor.getLockedStackFrame());
				}
			}
			strings.add("\tStack trace:");

			StackTraceElement[] stack = thread.getStackTrace();
			for (int line = 0; line < stack.length; line++)
			{
				strings.add("\t\t" + stack[line].toString());
			}
		}
	}
	strings.add("------------------------------------------------------------");
	strings.add("End of debugging information");
	strings.add("------------------------------------------------------------");

	return strings;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:42,代码来源:DebugHandler.java

示例12: appendThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Print all of the thread's information and stack traces.
 * 
 * @param sb
 * @param info
 * @param indent
 */
public static void appendThreadInfo(StringBuilder sb,
                                    ThreadInfo info,
                                    String indent) {
  boolean contention = threadBean.isThreadContentionMonitoringEnabled();

  if (info == null) {
    sb.append(indent).append("Inactive (perhaps exited while monitoring was done)\n");
    return;
  }
  String taskName = getTaskName(info.getThreadId(), info.getThreadName());
  sb.append(indent).append("Thread ").append(taskName).append(":\n");
  
  Thread.State state = info.getThreadState();
  sb.append(indent).append("  State: ").append(state).append("\n");
  sb.append(indent).append("  Blocked count: ").append(info.getBlockedCount()).append("\n");
  sb.append(indent).append("  Waited count: ").append(info.getWaitedCount()).append("\n");
  if (contention) {
    sb.append(indent).append("  Blocked time: " + info.getBlockedTime()).append("\n");
    sb.append(indent).append("  Waited time: " + info.getWaitedTime()).append("\n");
  }
  if (state == Thread.State.WAITING) {
    sb.append(indent).append("  Waiting on ").append(info.getLockName()).append("\n");
  } else  if (state == Thread.State.BLOCKED) {
    sb.append(indent).append("  Blocked on ").append(info.getLockName()).append("\n");
    sb.append(indent).append("  Blocked by ").append(
      getTaskName(info.getLockOwnerId(), info.getLockOwnerName())).append("\n");
  }
  sb.append(indent).append("  Stack:").append("\n");
  for (StackTraceElement frame: info.getStackTrace()) {
    sb.append(indent).append("    ").append(frame.toString()).append("\n");
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:40,代码来源:ThreadMonitoring.java

示例13: dumpThreads

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public static void dumpThreads(String file) throws IOException {
    StringBuilder dump = new StringBuilder();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
    for (ThreadInfo threadInfo : threadInfos) {
        dump.append('"');
        dump.append(threadInfo.getThreadName());
        dump.append("\" ");
        final Thread.State state = threadInfo.getThreadState();
        dump.append("\n   java.lang.Thread.State: ");
        dump.append(state);
        final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
        for (final StackTraceElement stackTraceElement : stackTraceElements) {
            dump.append("\n        at ");
            dump.append(stackTraceElement);
        }
        dump.append("\n\n");
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(dump.toString().getBytes(Charset.defaultCharset()));
    try(FileOutputStream fos = new FileOutputStream(file)) {
        byte[] buffer = new byte[1024];
        int read;
        while((read = bais.read(buffer)) > -1) {
            fos.write(buffer, 0, read);
        }
    }
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:28,代码来源:DumpUtils.java

示例14: printThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Print all of the thread's information and stack traces.
 * 
 * @param stream the stream to
 * @param title a string title for the stack trace
 */
public synchronized static void printThreadInfo(PrintStream stream,
                                   String title) {
  final int STACK_DEPTH = 20;
  boolean contention = threadBean.isThreadContentionMonitoringEnabled();
  long[] threadIds = threadBean.getAllThreadIds();
  stream.println("Process Thread Dump: " + title);
  stream.println(threadIds.length + " active threads");
  for (long tid: threadIds) {
    ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH);
    if (info == null) {
      stream.println("  Inactive");
      continue;
    }
    stream.println("Thread " + 
                   getTaskName(info.getThreadId(),
                               info.getThreadName()) + ":");
    Thread.State state = info.getThreadState();
    stream.println("  State: " + state);
    stream.println("  Blocked count: " + info.getBlockedCount());
    stream.println("  Waited count: " + info.getWaitedCount());
    if (contention) {
      stream.println("  Blocked time: " + info.getBlockedTime());
      stream.println("  Waited time: " + info.getWaitedTime());
    }
    if (state == Thread.State.WAITING) {
      stream.println("  Waiting on " + info.getLockName());
    } else  if (state == Thread.State.BLOCKED) {
      stream.println("  Blocked on " + info.getLockName());
      stream.println("  Blocked by " + 
                     getTaskName(info.getLockOwnerId(),
                                 info.getLockOwnerName()));
    }
    stream.println("  Stack:");
    for (StackTraceElement frame: info.getStackTrace()) {
      stream.println("    " + frame.toString());
    }
  }
  stream.flush();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:46,代码来源:ReflectionUtils.java

示例15: doThreadUpdates

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void doThreadUpdates() {
    ThreadMXBean threadMXBean =
            ManagementFactory.getThreadMXBean();
    long threadIds[] = 
            threadMXBean.getAllThreadIds();
    ThreadInfo[] threadInfos =
            threadMXBean.getThreadInfo(threadIds, 0);
    
    int threadsNew = 0;
    int threadsRunnable = 0;
    int threadsBlocked = 0;
    int threadsWaiting = 0;
    int threadsTimedWaiting = 0;
    int threadsTerminated = 0;
    
    for (ThreadInfo threadInfo : threadInfos) {
        // threadInfo is null if the thread is not alive or doesn't exist
        if (threadInfo == null) continue;
        Thread.State state = threadInfo.getThreadState();
        if (state == NEW) {
            threadsNew++;
        } 
        else if (state == RUNNABLE) {
            threadsRunnable++;
        }
        else if (state == BLOCKED) {
            threadsBlocked++;
        }
        else if (state == WAITING) {
            threadsWaiting++;
        } 
        else if (state == TIMED_WAITING) {
            threadsTimedWaiting++;
        }
        else if (state == TERMINATED) {
            threadsTerminated++;
        }
    }
    metrics.setMetric("threadsNew", threadsNew);
    metrics.setMetric("threadsRunnable", threadsRunnable);
    metrics.setMetric("threadsBlocked", threadsBlocked);
    metrics.setMetric("threadsWaiting", threadsWaiting);
    metrics.setMetric("threadsTimedWaiting", threadsTimedWaiting);
    metrics.setMetric("threadsTerminated", threadsTerminated);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:46,代码来源:JvmMetrics.java


注:本文中的java.lang.management.ThreadInfo.getThreadState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。