class My implements Runnable
{
int i=1;
boolean flag=true;
public void run()
{
while(flag)
{
try
{
System.out.println (Thread.currentThread().getName()+" sell ticket: "+i);
i++;
if(i>100)
flag=false;
Thread.sleep(10);
}
catch (Exception ex) {
}
}
}
}
class thread
{
public static void main(String[] args)
{
My my=new My();
Thread thr=new Thread(my);
Thread thr2=new Thread(my);
Thread thr3=new Thread(my);
Thread thr4=new Thread(my);
thr.start();
thr2.start();
thr3.start();
thr4.start();
}
}
{
int i=1;
boolean flag=true;
public void run()
{
while(flag)
{
try
{
System.out.println (Thread.currentThread().getName()+" sell ticket: "+i);
i++;
if(i>100)
flag=false;
Thread.sleep(10);
}
catch (Exception ex) {
}
}
}
}
class thread
{
public static void main(String[] args)
{
My my=new My();
Thread thr=new Thread(my);
Thread thr2=new Thread(my);
Thread thr3=new Thread(my);
Thread thr4=new Thread(my);
thr.start();
thr2.start();
thr3.start();
thr4.start();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货