可以将 main() 转换为守护线程
Converting main() into a daemon thread possible
据我所知,Java中的main()
默认是非守护线程,是否可以将其转换为守护线程?
如果只有守护线程 运行ning 那么 JVM 将关闭。如果主线程是守护线程,则程序无法 运行 不立即关闭。此外,您不能在线程启动后在线程上设置守护进程 属性,您不能在 运行ning:
期间将非守护线程更改为守护线程
public final void setDaemon(boolean on)
Marks this thread as either a daemon thread or a user thread. The Java
Virtual Machine exits when the only threads running are all daemon
threads.
This method must be invoked before the thread is started.
据我所知,Java中的main()
默认是非守护线程,是否可以将其转换为守护线程?
如果只有守护线程 运行ning 那么 JVM 将关闭。如果主线程是守护线程,则程序无法 运行 不立即关闭。此外,您不能在线程启动后在线程上设置守护进程 属性,您不能在 运行ning:
期间将非守护线程更改为守护线程public final void setDaemon(boolean on)
Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads.
This method must be invoked before the thread is started.