package animal;class HelloThread implements Runnable{int i;public void run(){ i=0;
System.out.println("当前线程"+Thread.currentThread());//第一个
while(true)
{
System.out.println("当前线程"+Thread.currentThread().getName());
System.out.println("Hello"+i++);
if(i>5)
break;
}
}}public class text{public static void main(String[]args){HelloThread r=new HelloThread();Thread t=new Thread(r);Thread t2=new Thread(r);t.start();t2.start();}}结果当前线程Thread[Thread-1,5,main]当前线程Thread-1当前线程Thread[Thread-0,5,main]当前线程Thread-0Hello1当前线程Thread-0Hello2Hello0当前线程Thread-1Hello3当前线程Thread-1Hello4当前线程Thread-1Hello5当前线程Thread-0Hello6为什么【第一个】那里的返回了2个地址,上面Hello1前有4个【当前线程。。。。】他们是有先后顺序的吗
添加回答
举报
0/150
提交
取消