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


Java ThreadInfo.getStackTrace方法代码示例

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


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

示例1: countThreads

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Count the number of threads that have a stack frame containing
 * the given string
 */
protected static int countThreads(String search) {
  ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

  int count = 0;
  ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
  for (ThreadInfo info : infos) {
    if (info == null) continue;
    for (StackTraceElement elem : info.getStackTrace()) {
      if (elem.getClassName().contains(search)) {
        count++;
        break;
      }
    }
  }
  return count;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:TestRpcBase.java

示例2: render

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
@Override
protected void render(Block html) {
  set(TITLE, join("Angel ExecutorsBlock"));
  TBODY<TABLE<Hamlet>> tbody =
      html.h1("ExecutorsBlock").table("#jobs").thead().tr().th(_TH, "id").th(_TH, "name")
          .th(_TH, "state").th(_TH, "stacktrace")._()._().tbody();

  ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
  ThreadInfo[] threadInfo = threadMXBean.dumpAllThreads(true, true);
  StringBuilder stackTraceString;
  for (ThreadInfo t : threadInfo) {
    stackTraceString = new StringBuilder();
    StackTraceElement[] stackTrace = t.getStackTrace();
    for (StackTraceElement s : stackTrace) {
      stackTraceString.append(s.toString()).append("\n");
    }
    tbody.tr().td(String.valueOf(t.getThreadId())).td(String.valueOf(t.getThreadName()))
        .td(String.valueOf(t.getThreadState())).td(String.valueOf(stackTraceString.toString()))._();
  }
  tbody._()._();


}
 
开发者ID:Tencent,项目名称:angel,代码行数:24,代码来源:ExecutorsBlock.java

示例3: getThreadStack

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Gets thread stack.
 *
 * @return the thread stack
 */
private String getThreadStack()
{
  ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
  ThreadInfo[] threadInfo =  threadMXBean.dumpAllThreads(true, true);
  StringBuilder stackTraceString= new StringBuilder("ParameterServer\n");
  StringBuilder infoBlock= new StringBuilder("\n");
  for(ThreadInfo t :  threadInfo)
  {
    infoBlock = new StringBuilder("\n\n");
    infoBlock.append("threadid: ").append(t.getThreadId()).append(" threadname: ").append(t.getThreadName()).append("       threadstate: ").append(t.getThreadState()).append("\n");
    for(StackTraceElement stackTraceElement : t.getStackTrace())
    {
      infoBlock.append("   ").append(stackTraceElement.toString()).append("\n");
    }
    stackTraceString.append(infoBlock).append("\n\n");
  }
  return stackTraceString.toString();
}
 
开发者ID:Tencent,项目名称:angel,代码行数:24,代码来源:ParameterServerService.java

示例4: printThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void printThreadInfo(ThreadInfo ti, PrintWriter out) {
  // print thread information
  printThread(ti, out);

  // print stack trace with locks
  StackTraceElement[] stacktrace = ti.getStackTrace();
  MonitorInfo[] monitors = ti.getLockedMonitors();
  for (int i = 0; i < stacktrace.length; i++) {
    StackTraceElement ste = stacktrace[i];
    out.println(INDENT + "at " + ste.toString());
    for (MonitorInfo mi : monitors) {
      if (mi.getLockedStackDepth() == i) {
        out.println(INDENT + "  - locked " + mi);
      }
    }
  }
  out.println();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:TimedOutTestsListener.java

示例5: findStack

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private boolean findStack(final List<String[]> stack, final ThreadInfo[] threads) {      
    for (ThreadInfo t : threads) {
        StackTraceElement[] els = t.getStackTrace();
        
        if (els == null || els.length < stack.size()) {
            continue;
        }
        int j=0;
        for (; j<stack.size(); j++) {
            StackTraceElement el = els[els.length - j - 1];
            String[] method = stack.get(j);
            
            if (!el.getClassName().equals(method[0]) || !el.getMethodName().equals(method[1])) {
                break;  // try next thread
            }
        }
        if (j == stack.size()) { // match
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:SampledCPUSnapshot.java

示例6: countTimerThreads

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static int countTimerThreads() {
  ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
  
  int count = 0;
  ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
  for (ThreadInfo info : infos) {
    if (info == null) continue;
    for (StackTraceElement elem : info.getStackTrace()) {
      if (elem.getClassName().contains("Timer")) {
        count++;
        break;
      }
    }
  }
  return count;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:TestShell.java

示例7: countThreads

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Count the number of threads that have a stack frame containing
 * the given string
 */
private static int countThreads(String search) {
  ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

  int count = 0;
  ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
  for (ThreadInfo info : infos) {
    if (info == null) continue;
    for (StackTraceElement elem : info.getStackTrace()) {
      if (elem.getClassName().contains(search)) {
        count++;
        break;
      }
    }
  }
  return count;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestRPC.java

示例8: 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

示例9: isIdleThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static boolean isIdleThread(ThreadInfo threadInfo) {
    String threadName = threadInfo.getThreadName();

    // NOTE: these are likely JVM dependent
    if (threadName.equals("Signal Dispatcher") ||
        threadName.equals("Finalizer") ||
        threadName.equals("Reference Handler")) {
        return true;
    }
        
    for (StackTraceElement frame : threadInfo.getStackTrace()) {
        String className = frame.getClassName();
        String methodName = frame.getMethodName();
        if (className.equals("java.util.concurrent.ThreadPoolExecutor") &&
            methodName.equals("getTask")) {
            return true;
        }
        if (className.equals("sun.nio.ch.SelectorImpl") &&
            methodName.equals("select")) {
            return true;
        }
        if (className.equals("org.elasticsearch.threadpool.ThreadPool$EstimatedTimeThread") &&
            methodName.equals("run")) {
            return true;
        }
        if (className.equals("org.elasticsearch.indices.ttl.IndicesTTLService$Notifier") &&
            methodName.equals("await")) {
            return true;
        }
        if (className.equals("java.util.concurrent.LinkedTransferQueue") &&
            methodName.equals("poll")) {
            return true;
        }
    }

    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:38,代码来源:HotThreads.java

示例10: 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
 */
private 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:fengchen8086,项目名称:ditb,代码行数:46,代码来源:ReflectionUtils.java

示例11: writeSample

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
void writeSample(ThreadInfo[] infos, long time, long selfThreadId) throws IOException {
    List<Long> sameT = new ArrayList();
    List<ThreadInfo> newT = new ArrayList();
    List<Long> tids = new ArrayList();

    for (ThreadInfo tinfo : infos) {
        long id;

        if (tinfo == null) continue;    // ignore null ThreadInfo
        id = tinfo.getThreadId();
        if (id != selfThreadId) { // ignore sampling thread
            Long tid = Long.valueOf(tinfo.getThreadId());
            ThreadInfo lastThread = lastThreadInfos.get(tid);

            tids.add(tid);
            if (lastThread != null) {
                if (lastThread.getThreadState().equals(tinfo.getThreadState())) {
                    StackTraceElement[] lastStack = lastThread.getStackTrace();
                    StackTraceElement[] stack = tinfo.getStackTrace();

                    if (Arrays.deepEquals(lastStack, stack)) {
                        sameT.add(tid);
                        continue;
                    }
                }
            }
            internStackTrace(tinfo);
            newT.add(tinfo);
            lastThreadInfos.put(tid, tinfo);
        }
    }
    addSample(new Sample(time, sameT, newT));
    // remove dead threads
    Set<Long> ids = new HashSet(lastThreadInfos.keySet());
    ids.removeAll(tids);
    lastThreadInfos.keySet().removeAll(ids);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:SamplesOutputStream.java

示例12: 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,项目名称:NapBot,代码行数:42,代码来源:DebugHandler.java

示例13: 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

示例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 static void printThreadInfo(PrintWriter 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:spafka,项目名称:spark_deep,代码行数:46,代码来源:ReflectionUtils.java

示例15: 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


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