isAlive():表示线程是否还活着
currentThread():当前线程
setName()、getName():代理名称
package Thread;
/**
* 测试线程其它方法
* @author Administrator
*
*/
public class MyInfoTest {
public static void main(String[] args) throws InterruptedException {
System.out.println(Thread.currentThread().isAlive());
Info info = new Info("战斗机");
Thread t = new Thread(info);
t.setName("公鸡");
t.start();
Thread.sleep(1000);
System.out.println(t.isAlive());
}
}
class Info implements Runnable{
private String name;
public Info(String name) {
super();
this.name = name;
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"-->"+name);
}
}
显示结果:
true
公鸡-->战斗机
false