package com.anyan;
/**
* @author anyan
* @date 2021/5/4-15:47
*/
public class ThreadEndTest {
public static void main(String[] args) {
Thread t=new Thread(new Student5());
t.start();
try {
t.sleep(1000*5);
} catch (InterruptedException e) {
e.printStackTrace();
}
//该方法的缺陷在于:线程终止前的状态还没有保存就已经被终止。
t.stop();//该方法用于终止线程,已过时,易造成死锁问题,不建议使用
//Thread.currentThread().setName("主线程");
/*for(int i=0;i<10;i++){
System.out.println(Thread.currentThread().getName()+"----->"+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}*/
}
}
class Student5 implements Runnable{
@Override
public void run() {
for (int i = 0; i < 10; i++) {
Thread.currentThread().setName("分支线程");
System.out.println(Thread.currentThread().getName());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}