转换用户线程的使用->守护线程
我读到,守护线程是由 JVM 使用和控制的。 JVM 创建它们并负责它们的终止。用户线程由用户控制。 也有人说,我们可以通过调用 setDaemon() 方法将用户线程转换为守护线程。
但是,这种转换有什么用
?一旦用户线程成为守护线程,JVM 是否会控制用户线程?
如果我错过了什么,请告诉我。
谢谢。
I read, daemon threads are used and controlled by JVM. JVM creates them and also looks after their termination.User threads are controlled by user.
It is also said, we can convert a user thread to daemon thread by calling setDaemon()
method.
But, what is the use of such conversion
? Does JVM takes the control of user thread once it has become a dameon thread ?
Let me know if I missed something.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信用户和守护线程始终处于 JVM 的控制之下。 (如果不是这样,谁来负责?)
这是区别(来自 http://www.xyzws.com/javafaq/what-is-difference- Between-user-and-daemon-thread-in-java/196< /a>):
I believe that user and daemon threads are always under the JVM's control. (If that wasn't the case, who would be in charge?)
Here's the distinction (from http://www.xyzws.com/javafaq/what-is-difference-between-user-and-daemon-thread-in-java/196):
守护线程不会阻止应用程序在仍在工作时关闭。它们更适合在应用程序处于活动状态时需要完成的任务,但在其他情况下可以安全地终止。
Daemon threads don't prevent the application from shutting down while they're still doing work. They're more for tasks that need to be done while the app is alive, but are safe to kill off otherwise.