<legend id='rrku5'><style id='rrku5'><dir id='rrku5'><q id='rrku5'></q></dir></style></legend>

    <small id='rrku5'></small><noframes id='rrku5'>

    • <bdo id='rrku5'></bdo><ul id='rrku5'></ul>
  1. <i id='rrku5'><tr id='rrku5'><dt id='rrku5'><q id='rrku5'><span id='rrku5'><b id='rrku5'><form id='rrku5'><ins id='rrku5'></ins><ul id='rrku5'></ul><sub id='rrku5'></sub></form><legend id='rrku5'></legend><bdo id='rrku5'><pre id='rrku5'><center id='rrku5'></center></pre></bdo></b><th id='rrku5'></th></span></q></dt></tr></i><div id='rrku5'><tfoot id='rrku5'></tfoot><dl id='rrku5'><fieldset id='rrku5'></fieldset></dl></div>

      <tfoot id='rrku5'></tfoot>

      以编程方式触发完整的堆栈转储?

      时间:2023-08-23

        <small id='rp6DD'></small><noframes id='rp6DD'>

        <tfoot id='rp6DD'></tfoot>

              <bdo id='rp6DD'></bdo><ul id='rp6DD'></ul>
                  <tbody id='rp6DD'></tbody>
              • <legend id='rp6DD'><style id='rp6DD'><dir id='rp6DD'><q id='rp6DD'></q></dir></style></legend>
              • <i id='rp6DD'><tr id='rp6DD'><dt id='rp6DD'><q id='rp6DD'><span id='rp6DD'><b id='rp6DD'><form id='rp6DD'><ins id='rp6DD'></ins><ul id='rp6DD'></ul><sub id='rp6DD'></sub></form><legend id='rp6DD'></legend><bdo id='rp6DD'><pre id='rp6DD'><center id='rp6DD'></center></pre></bdo></b><th id='rp6DD'></th></span></q></dt></tr></i><div id='rp6DD'><tfoot id='rp6DD'></tfoot><dl id='rp6DD'><fieldset id='rp6DD'></fieldset></dl></div>

              • 本文介绍了以编程方式触发完整的堆栈转储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当我向我的 java 进程发送 SIGQUIT 命令时(使用 kill -3 或 kill -QUIT ),它会将所有堆栈的跟踪打印到 stderr,其中包含有关持有的锁和死锁检测的信息.我可以从程序内部以某种方式触发它吗?我想在每次某个操作花费太长时间时自动执行此操作.

                When I send a SIGQUIT command to my java process (using kill -3 or kill -QUIT ), it prints a trace of all stacks to stderr, with information about locks held, and deadlock detection. Can I trigger this from inside the program somehow? I want to do this automatically every time a certain operation takes too long.

                我知道可以获得堆栈跟踪(请参阅 有没有办法在不抛出异常的情况下转储堆栈跟踪?, 线程转储程序/JDI(Java调试器接口)).但我想查看所有内容:堆栈跟踪、线程状态、持有的锁、阻塞的锁、死锁检测等,即我发送 SIGQUIT 时得到的所有内容;不仅仅是堆栈跟踪.

                I know it's possible to get a stack trace (see Is there a way to dump a stack trace without throwing an exception in java?, Thread dump programmatically /JDI (Java Debugger Interface)). But I want to see the whole everything: stack traces, thread states, locks held, locks blocked on, deadlock detection, etc., i.e. everything I get when I sent a SIGQUIT; not just the stack trace.

                推荐答案

                是的,你可以.我一直在成功地使用此代码调试随机触发的并发错误:

                Yes you can. I've been using this code successfully to debug randomly triggered concurrency bugs:

                package utils.stack;
                
                import java.io.IOException;
                import java.io.UncheckedIOException;
                import java.lang.management.ManagementFactory;
                import java.nio.file.Files;
                import java.nio.file.Path;
                import java.nio.file.Paths;
                import java.time.LocalDateTime;
                import java.util.function.Supplier;
                import javax.management.JMX;
                import javax.management.MBeanServer;
                import javax.management.MalformedObjectNameException;
                import javax.management.ObjectName;
                
                public interface DiagnosticCommand {
                    String threadPrint(String... args);
                
                    DiagnosticCommand local = ((Supplier<DiagnosticCommand>) () -> {
                        try {
                            MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                            ObjectName name = new ObjectName("com.sun.management", 
                                "type", "DiagnosticCommand");
                            return JMX.newMBeanProxy(server, name, DiagnosticCommand.class);
                        } catch(MalformedObjectNameException e) {
                            throw new AssertionError(e);
                        }
                    }).get();
                
                    static void dump() {
                        String print = local.threadPrint();
                        Path path = Paths.get(LocalDateTime.now() + ".dump.txt");
                        try {
                            byte[] bytes = print.getBytes("ASCII");
                            Files.write(path, bytes);
                        } catch(IOException e) {
                            throw new UncheckedIOException(e);
                        }
                    }
                }
                

                它需要 Java 8 和 HotSpot 作为 JVM,因为它模仿 jstack 正在做的事情,除了在同一个进程中.

                It requires Java 8 and HotSpot as the JVM as it mimics what jstack is doing, except from within the same process.

                这篇关于以编程方式触发完整的堆栈转储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 Sigar API 获取 JVM CPU 使用率 下一篇:字符串实习在 Java 7+ 中如何工作?

                相关文章

              • <i id='IZg4h'><tr id='IZg4h'><dt id='IZg4h'><q id='IZg4h'><span id='IZg4h'><b id='IZg4h'><form id='IZg4h'><ins id='IZg4h'></ins><ul id='IZg4h'></ul><sub id='IZg4h'></sub></form><legend id='IZg4h'></legend><bdo id='IZg4h'><pre id='IZg4h'><center id='IZg4h'></center></pre></bdo></b><th id='IZg4h'></th></span></q></dt></tr></i><div id='IZg4h'><tfoot id='IZg4h'></tfoot><dl id='IZg4h'><fieldset id='IZg4h'></fieldset></dl></div>

                  <bdo id='IZg4h'></bdo><ul id='IZg4h'></ul>
                <legend id='IZg4h'><style id='IZg4h'><dir id='IZg4h'><q id='IZg4h'></q></dir></style></legend>

                  1. <small id='IZg4h'></small><noframes id='IZg4h'>

                    <tfoot id='IZg4h'></tfoot>