package gongFu;
class Lock
{
}
class Ticket002 implements Runnable
{
private int tick=100;
public void run() {
synchronized(new Lock()){
while(tick>0)
{
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("售票员"+Thread.currentThread().getName()+"正在卖第"+tick--+"张票");
}
}
}
}
public class Ticket02 {
public static void main(String[] args) {
Ticket002 tick=new Ticket002();
Thread t1=new Thread(tick);
t1.setName("亚由美");
Thread t2=new Thread(tick);
t2.setName("朴秀珍");
Thread t3=new Thread(tick);
t3.setName("李河琳");
Thread t4=new Thread(tick);
t4.setName("陆慧胜");
Thread t5=new Thread(tick);
t5.setName("黄静茵");
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
}
}
|
|