开发者

Why does the JVM not wait for daemon threads spawned by user application?

开发者 https://www.devze.com 2023-04-12 02:09 出处:网络
\"The virtual machine terminates if the last non-daemon thread has finished.\" My question is, What happens to the daemon threads 开发者_如何学Cspawned by the application? Why does the JVM not wait fo

"The virtual machine terminates if the last non-daemon thread has finished." My question is, What happens to the daemon threads 开发者_如何学Cspawned by the application? Why does the JVM not wait for them to finish?


The whole purpose of a daemon thread is that it not not keep the JVM alive if it is the only thread running; this is by design. There are many reasons you might wish to do this.

For example, with a Swing application the user may have invoked a long running task on a background daemon thread (as opposed to on the Event Dispatch thread). Prior to the task completing the user attempts to exit the application. At this stage the application developer may have decided that it is better to shut down the application immediately rather than have the shut-down attempt delayed until the long running computation completes, hence why these decided to assign the computation thread daemon status.


Because they're daemon threads. That's what it means. It doesn't mean anything else.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号