/**
* Created by xabcd on 2019/2/17.
*/
public class StratThread extends Thread
{
public void run()
{
for (int i = 0;i<10;i++);{
PrintMsg();
}
}
public void PrintMsg(){
Thread t = Thread.currentThread();
String name = t.getName();
System.out.println("name = "+name);
}
public static void main(String args[])
{
StratThread tt = new StratThread();
tt.setName("test Thread");
System.out.println("启动前:"+tt.isAlive());
tt.start();
System.out.println("刚启动:"+tt.isAlive());
for (int i = 0;i<3;i++)
{
tt.PrintMsg();
}
//下面语句结果是不固定的,又是输出true有时是false
System.out.println("main()方法结束时:"+tt.isAlive());
}
}
启动前:false
刚启动:true
name = main
name = main
name = main
main()方法结束时:true
name = test Thread
结果总是只有一个test Thread