package com.aflfte.state;
/**
* 线程的其它方法
* isAlive:判断线程是否已经终止
* Thread.currentThread() :表示 当前线程
* setName :设置线程名称
* getName:获取线程名称
* @author jinhao
*
*/
public class InfoTest {
public static void main(String[] args) {
System.out.println(Thread.currentThread().isAlive());//isAlive 判断当前线程是否已终止
//给线程设置名称 真实角色+代理角色
MyInfo info=new MyInfo("战斗机");//设置真实角色名称
Thread t=new Thread(info);
t.setName("张三");//设置代理角色名称
t.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println(t.isAlive());
}
}
class MyInfo implements Runnable{
private String name;
public MyInfo(String name) {
super();
this.name = name;
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"-->"+name);
}
}
« 多线程安全同步(synchronized的使用方法)
|
守护线程»
|