- class Deamo implements Runnable{
- public void run() {
- int i=0;
- while(true){
- System.out.println(Thread.currentThread().getName()+" "+i++);
- }
-
- }
-
- }
- public class DeamonDemo {
- public static void main(String[] args) {
-
- Deamo d = new Deamo();
-
- Thread t = new Thread(d);
-
- t.setDaemon(true);
-
- t.start();
-
- for(int i =0;i<=60;i++){
- System.out.println(Thread.currentThread().getName()+" "+i);
- }
- }
- }
复制代码
为什么主线程停止了,线程依然运行了一会
|
|