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

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

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

      Java中的主线程什么时候停止?

      When does the main thread stop in Java?(Java中的主线程什么时候停止?)

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

          <bdo id='rEFJx'></bdo><ul id='rEFJx'></ul>

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

                <legend id='rEFJx'><style id='rEFJx'><dir id='rEFJx'><q id='rEFJx'></q></dir></style></legend><tfoot id='rEFJx'></tfoot>
                本文介绍了Java中的主线程什么时候停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我读了这个声明:

                主线程必须是完成执行的最后一个线程.当主线程停止时,程序终止.

                The main thread must be the last thread to finish execution. When the main thread stops, the program terminates.

                是真的吗?

                我也开始知道即使主线程死了,程序也会继续运行".

                I also came to know "Even if the main thread dies, the program keeps running".

                这是我目前的理解:

                • 当您启动一个程序时,JVM 会创建一个线程来运行您的程序.
                • JVM 创建一个用户线程来运行程序.这个线程称为主线程.
                • 从主线程调用类的main方法.
                • 如果程序从主线程产生新线程,程序会一直等待,直到最后一个线程终止.

                哪一个是真的?

                推荐答案

                当所有非守护线程都死掉时程序终止(守护线程是用 setDaemon(true) 标记的线程;通常是用于实用程序线程).来自文档:

                The program terminates when all non-daemon threads die (a daemon thread is a thread marked with setDaemon(true); it's usually used for utility threads). From the documentation:

                当 Java 虚拟机启动时,通常有一个非守护线程(通常调用某个指定类的名为 main 的方法).Java 虚拟机继续执行线程,直到发生以下任一情况:

                When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:

                • 已调用 Runtime 类的退出方法,并且安全管理器已允许执行退出操作.
                • 不是守护线程的所有线程都已死亡,要么从调用 run 方法返回,要么抛出传播到 run 方法之外的异常.

                这篇关于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 中的默认语言环境设置以使其保持一致?)

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

                  • <small id='KHUPM'></small><noframes id='KHUPM'>

                      <tfoot id='KHUPM'></tfoot>

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