/**
* isAlive():线程是否还活着
* Thread.currentThread():当前线程
* setName, getName:代理名称
*/
public class infoTest {
public static void main(String[] args) throws InterruptedException {
MyInfo myInfo = new MyInfo("战斗机");
Thread t = new Thread(myInfo,"公鸡");
t.start();
Thread.sleep(1000);
System.out.println(t.isAlive());
}
}
class MyInfo implements Runnable{
private String name;
public MyInfo(String name) {
this.name = name;
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + "--->" + this.name);
}
}
运行结果
公鸡--->战斗机
false