public class dddd extends Thread
{
static int i=100;
public synchronized void run()
{
while(i>0){
System.out.println(Thread.currentThread().getName()+" "+i);
i--;
}
}
public static void main(String[] args)
{
dddd h=new dddd();
Thread a=new Thread(h);
Thread b=new Thread(h);
Thread c=new Thread(h);
Thread d=new Thread(h);
Thread e=new Thread(h);
a.start();
b.start();
c.start();
d.start();
e.start();
}
}
要线程停止,只需要run方法运行完就自动停止了 |