class Randomarr implements Runnable
{
privateint i=0;
public void run()
{
if( i<6)
{
System.out.println(Thread.currentThread().getName()+"...."+(int)(Math.random()*20)+"....."+i++);
}
}
}
public class DT_di10dan {
publicstatic int arr[]=new int[6];
publicstatic void main(String[] args)
{
Randomarrr=new Randomarr();
Threadt1=new Thread(r,"线程1");
Threadt2=new Thread(r,"线程2");
t1.start();
t2.start();
int j=6;
while(j!=0)
{
System.out.println("..."+j--);
}
System.out.println("over");
}
}
运行结果如下:
两个线程为什么会停止?它们的运行原理是什么?
|
|