Java应用程序生命周期
典型的 Java 应用程序何时完成?
如果我在 main
方法中启动一个新线程,然后 main
方法完成,但另一个线程继续工作,则应用程序仍将处于运行状态,直到所有线程都终止,不是吗?
谢谢&圣诞快乐!
When does a typical Java app finish?
If I start a new thread in the main
method and then the main
method finishes, but the other thread continues working, the app would still be on until all it's threads have died, wouldn't it?
Thanks & Merry Christmas!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,除非它是守护线程。引用线程API:
Yes, unless it's a deamon thread. Quoting from Thread API:
main() 函数定义您的主用户线程。您可能还创建了其他用户线程。您可能还对其中一些线程调用了 setDeamon()。
JVM 将在以下情况下结束:
The main() function defines your main user thread. You might have other user threads that you created as well. You might also have called setDeamon() on some of those threads.
The JVM will end when: