当前位置: 首页>>代码示例>>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;未经允许,请勿转载。