public class SimpleThread{
public static void main(String[] args){
System.out.println("主线程开始");
Thread thread = new Thread(new Runnable(){
public void run(){
while(true){
System.out.println("t");
}
}
});
thread.start();
System.out.println("主线程结束");
}
}
java SimpleThread,then,Ctrl+C:
解决:
1、ctrl+c;
2、System.exit();
=================================================================================================
Daemon线程:
1、如果所有的费Daemon线程结束了,这Daemon线程自动终止!
2、Daemon线程产生的线程也是Daemon线程;
3、setDaemon();isDaemon();
public class SimpleThread{
public static void main(String[] args){
System.out.println("主线程开始");
Thread thread = new Thread(new Runnable(){
public void run(){
while(true){
System.out.println("t");
}
}
});
thread.setDaemon(true);
thread.start();
System.out.println("主线程结束");
}
}