gpt4 book ai didi

Java应用程序生命周期

转载 作者:行者123 更新时间:2023-12-02 12:12:00 24 4
gpt4 key购买 nike

典型的 Java 应用程序何时完成?

如果我在 main 方法中启动一个新线程,然后 main 方法完成,但另一个线程继续工作,则应用程序仍将运行,直到全部完成为止。线程已经死了,不是吗?

谢谢,圣诞快乐!

最佳答案

是的,除非它是守护线程。引用自Thread API :

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:

  • The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
  • All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.

关于Java应用程序生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4540152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com