當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadMXBean.dumpAllThreads方法代碼示例

本文整理匯總了Java中java.lang.management.ThreadMXBean.dumpAllThreads方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadMXBean.dumpAllThreads方法的具體用法?Java ThreadMXBean.dumpAllThreads怎麽用?Java ThreadMXBean.dumpAllThreads使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.management.ThreadMXBean的用法示例。


在下文中一共展示了ThreadMXBean.dumpAllThreads方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: render

import java.lang.management.ThreadMXBean; //導入方法依賴的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

示例2: getThreadStack

import java.lang.management.ThreadMXBean; //導入方法依賴的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

示例3: isMonitorLockHeldByThread

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
public static boolean isMonitorLockHeldByThread(Object o, Thread t) {
    int oihc = System.identityHashCode(o);
    ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] tinfos = tmxbean.dumpAllThreads(true, false);

    for (ThreadInfo ti : tinfos) {
        if (!(t != null && t.getId() != ti.getThreadId())) {
            for (MonitorInfo mi : ti.getLockedMonitors()) {
                if (mi.getIdentityHashCode() == oihc) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:GraalOSRLockTest.java

示例4: dumpTestThreads

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
/**
 * 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;
        System.err.print(info);
    }
    System.err.println("------ stacktrace dump end ------");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ConcurrentAssociateTest.java

示例5: dumpTestThreads

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
/**
 * 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 ------");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:Basic.java

示例6: getThreadStack

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
private String getThreadStack() {
  ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
  ThreadInfo[] threadInfo = threadMXBean.dumpAllThreads(true, true);
  StringBuilder stackTraceString = new StringBuilder("Worker\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,代碼行數:16,代碼來源:WorkerService.java

示例7: dumpTestThreads

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
/**
 * A debugging tool to print stack traces of most threads, as jstack does.
 * Uninteresting threads are filtered out.
 */
static void dumpTestThreads() {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            System.setSecurityManager(null);
        } catch (SecurityException giveUp) {
            return;
        }
    }

    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    System.err.println("------ stacktrace dump start ------");
    for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
        final String name = info.getThreadName();
        String lockName;
        if ("Signal Dispatcher".equals(name))
            continue;
        if ("Reference Handler".equals(name)
            && (lockName = info.getLockName()) != null
            && lockName.startsWith("java.lang.ref.Reference$Lock"))
            continue;
        if ("Finalizer".equals(name)
            && (lockName = info.getLockName()) != null
            && lockName.startsWith("java.lang.ref.ReferenceQueue$Lock"))
            continue;
        if ("checkForWedgedTest".equals(name))
            continue;
        System.err.print(info);
    }
    System.err.println("------ stacktrace dump end ------");

    if (sm != null) System.setSecurityManager(sm);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:JSR166TestCase.java

示例8: run

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
public void run()
{
    while (this.server.isServerRunning())
    {
        long i = this.server.getCurrentTime();
        long j = MinecraftServer.getCurrentTimeMillis();
        long k = j - i;

        if (k > this.maxTickTime)
        {
            LOGGER.fatal("A single server tick took " + String.format("%.2f", new Object[] {Float.valueOf((float)k / 1000.0F)}) + " seconds (should be max " + String.format("%.2f", new Object[] {Float.valueOf(0.05F)}) + ")");
            LOGGER.fatal("Considering it to be crashed, server will forcibly shutdown.");
            ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
            ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
            StringBuilder stringbuilder = new StringBuilder();
            Error error = new Error();

            for (ThreadInfo threadinfo : athreadinfo)
            {
                if (threadinfo.getThreadId() == this.server.getServerThread().getId())
                {
                    error.setStackTrace(threadinfo.getStackTrace());
                }

                stringbuilder.append((Object)threadinfo);
                stringbuilder.append("\n");
            }

            CrashReport crashreport = new CrashReport("Watching Server", error);
            this.server.addServerInfoToCrashReport(crashreport);
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Thread Dump");
            crashreportcategory.addCrashSection("Threads", stringbuilder);
            File file1 = new File(new File(this.server.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");

            if (crashreport.saveToFile(file1))
            {
                LOGGER.error("This crash report has been saved to: " + file1.getAbsolutePath());
            }
            else
            {
                LOGGER.error("We were unable to save this crash report to disk.");
            }

            this.scheduleHalt();
        }

        try
        {
            Thread.sleep(i + this.maxTickTime - j);
        }
        catch (InterruptedException var15)
        {
            ;
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:57,代碼來源:ServerHangWatchdog.java

示例9: dumpAllThreads

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
static void dumpAllThreads(Consumer<String> println) {
  final ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
  for (ThreadInfo ti : threadMxBean.dumpAllThreads(true, true)) {
    println.accept(ti.toString());
  }
}
 
開發者ID:apache,項目名稱:incubator-ratis,代碼行數:7,代碼來源:JavaUtils.java

示例10: getCurrentInfo

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
public Map<Thread.State, Long> getCurrentInfo(MBeanServerConnection connection) {

        ThreadMXBean threadBean = JMX.newMXBeanProxy(connection, threadsName, ThreadMXBean.class);
        ThreadInfo[] threads = threadBean.dumpAllThreads(false,false);

        // take copy of map with all possible states initialised to zero
        EnumMap<Thread.State, Long> threadStates = initialThreadStates.clone();

        for(ThreadInfo thread : threads) {
            Thread.State state = thread.getThreadState();
            threadStates.put(state, threadStates.get(state)+1);
        }

        return threadStates;

    }
 
開發者ID:breakEval13,項目名稱:rocketmq-flink-plugin,代碼行數:17,代碼來源:JMXThreadInfo.java

示例11: run

import java.lang.management.ThreadMXBean; //導入方法依賴的package包/類
public void run()
{
    while (this.server.isServerRunning())
    {
        long i = this.server.getCurrentTime();
        long j = MinecraftServer.getCurrentTimeMillis();
        long k = j - i;

        if (k > this.maxTickTime && !this.firstRun)
        {
            LOGGER.fatal("A single server tick took {} seconds (should be max {})", new Object[] {String.format("%.2f", new Object[]{Float.valueOf((float)k / 1000.0F)}), String.format("%.2f", new Object[]{Float.valueOf(0.05F)})});
            LOGGER.fatal("Considering it to be crashed, server will forcibly shutdown.");
            ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
            ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
            StringBuilder stringbuilder = new StringBuilder();
            Error error = new Error();

            for (ThreadInfo threadinfo : athreadinfo)
            {
                if (threadinfo.getThreadId() == this.server.getServerThread().getId())
                {
                    error.setStackTrace(threadinfo.getStackTrace());
                }

                stringbuilder.append((Object)threadinfo);
                stringbuilder.append("\n");
            }

            CrashReport crashreport = new CrashReport("Watching Server", error);
            this.server.addServerInfoToCrashReport(crashreport);
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Thread Dump");
            crashreportcategory.addCrashSection("Threads", stringbuilder);
            File file1 = new File(new File(this.server.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");

            if (crashreport.saveToFile(file1))
            {
                LOGGER.error("This crash report has been saved to: {}", new Object[] {file1.getAbsolutePath()});
            }
            else
            {
                LOGGER.error("We were unable to save this crash report to disk.");
            }

            this.scheduleHalt();
        }

        this.firstRun = false;

        try
        {
            Thread.sleep(i + this.maxTickTime - j);
        }
        catch (InterruptedException var15)
        {
            ;
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:59,代碼來源:ServerHangWatchdog.java


注:本文中的java.lang.management.ThreadMXBean.dumpAllThreads方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。