终止线程的典型方法
public class TestDeadLock implements Runnable{
String name;
boolean live=true;
public TestDeadLock(String name) {
super();
this.name = name;
}
public void run(){
int i=0;
while(live){
System.out.println(name+(i++));
}
}
public void terminate(){
live=false;
}
public static void main(String[] args) {
TestDeadLock ttc=new TestDeadLock("线程1:");
Thread t1=new Thread(ttc);
t1.start();
for(int i=0;i<100;i++){
System.out.println(i);
}
ttc.terminate();
System.out.println("ttc stop!");
}
}