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

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

        <bdo id='D3wGE'></bdo><ul id='D3wGE'></ul>
      <tfoot id='D3wGE'></tfoot>

      1. 当我的 Java 应用程序退出/崩溃时,如何摆脱 Java 子进程?

        How do I get rid of Java child processes when my Java app exits/crashes?(当我的 Java 应用程序退出/崩溃时,如何摆脱 Java 子进程?)

              <tbody id='i4DAw'></tbody>
          • <legend id='i4DAw'><style id='i4DAw'><dir id='i4DAw'><q id='i4DAw'></q></dir></style></legend>

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

                • <bdo id='i4DAw'></bdo><ul id='i4DAw'></ul>

                  <tfoot id='i4DAw'></tfoot>
                  <i id='i4DAw'><tr id='i4DAw'><dt id='i4DAw'><q id='i4DAw'><span id='i4DAw'><b id='i4DAw'><form id='i4DAw'><ins id='i4DAw'></ins><ul id='i4DAw'></ul><sub id='i4DAw'></sub></form><legend id='i4DAw'></legend><bdo id='i4DAw'><pre id='i4DAw'><center id='i4DAw'></center></pre></bdo></b><th id='i4DAw'></th></span></q></dt></tr></i><div id='i4DAw'><tfoot id='i4DAw'></tfoot><dl id='i4DAw'><fieldset id='i4DAw'></fieldset></dl></div>
                • 本文介绍了当我的 Java 应用程序退出/崩溃时,如何摆脱 Java 子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Java 中启动一个子进程如下:

                  I launch a child process in Java as follows:

                  final String[] cmd = {"<childProcessName>"};
                  Process process = Runtime.getRuntime().exec(cmd);
                  

                  它现在在后台运行.一切都很好.

                  It now runs in the background. All good and fine.

                  如果我的程序现在崩溃了(它仍在开发中:-))子进程似乎仍然徘徊.当父 Java 进程死亡时,如何使其自动结束?

                  If my program now crashes (it is still in dev :-)) the child process still seems to hang around. How can I make it automatically end when the parent Java process dies?

                  如果有帮助,我使用的是 Mac OS X 10.5

                  If it helps, I'm using Mac OS X 10.5

                  推荐答案

                  如你所说,addShutdownHook 是要走的路.

                  As you said, addShutdownHook is the way to go.

                  但是:

                  • 如果程序终止,并不能真正保证您的关闭挂钩会被执行.有人可能会杀死 Java 进程,在这种情况下,您的关闭挂钩将不会被执行.(如本 SO question 中所述)

                  一些标准库有自己的钩子,可能在你之前运行.

                  some of the standard libraries have their own hooks which may run before yours.

                  小心死锁.

                  另一种可能性是将您的 java 程序包装在一个服务中.

                  这篇关于当我的 Java 应用程序退出/崩溃时,如何摆脱 Java 子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <tfoot id='Ryhg5'></tfoot>
                    1. <legend id='Ryhg5'><style id='Ryhg5'><dir id='Ryhg5'><q id='Ryhg5'></q></dir></style></legend>
                          <bdo id='Ryhg5'></bdo><ul id='Ryhg5'></ul>
                        • <small id='Ryhg5'></small><noframes id='Ryhg5'>

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

                              <tbody id='Ryhg5'></tbody>