【发布时间】:2015-07-01 04:18:57
【问题描述】:
我想将主线程设为守护线程,但它显示IllegalThreadStateException。
有什么办法吗?
public class DeamonThreads {
public static void main(String[] args) {
System.out.println("Main Started");
System.out.println("Thread type deamon = " + Thread.currentThread().isDaemon());
Thread.currentThread().setDaemon(true);
System.out.println("Thread type deamon = " + Thread.currentThread().isDaemon());
System.out.println("Main End");
}
}
输出
Main Started
Thread type deamon = false
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.setDaemon(Thread.java:1367)
at com.threads.DeamonThreads.main(DeamonThreads.java:8)
【问题讨论】:
-
你为什么要这么做?
标签: java multithreading daemon