if main method completes the execution, what happens to any long running thread?

后端 未结 3 736
小鲜肉
小鲜肉 2021-01-17 12:35

since main() runs on a thread. and as soon as the main() finishes, main-thread should stop. So if main() has invoked a long running th

3条回答
  •  我在风中等你
    2021-01-17 12:38

    To answer your question why, it's because making your thread a non-daemon thread means that you don't want it to be terminated abruptly, you want it to be terminated in an orderly way by running to completion or by being canceled. If your thread was killed by the JVM once main was exited that would be equivalent to making the thread a daemon.

提交回复
热议问题