-->
当前位置:首页 > 题库 > 正文内容

程序填空题:jmu-Java-07多线程-守护线程

Luz4年前 (2021-05-10)题库1839
本题要求主线程退出时,在main方法中所启动的线程`t1`也要自动结束。

```Java
public class Main {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(new PrintTask());
@@[t1.setDaemon(true);](2)
@@[t1.start();](1)
System.out.println(Thread.currentThread().getName() + " end");
}
}
```





答案:
第1空:t1.setDaemon(true);

第2空:t1.start();

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。