据我所知,Java中的main()
默认是一个非守护线程,是否可以将其转换为守护线程?
最佳答案
如果只有守护线程在运行,那么 JVM 将关闭。如果主线程是守护线程,那么程序必须立即关闭才能运行。此外,您不能在线程启动后在其上设置守护进程属性,您不能在运行时将非守护线程更改为守护线程:
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() 转换为守护线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32726757/