- /*
- 需求:简单的卖票程序
- 多个窗口同时买票
- */
- class Ticket implements Runnable//extends Thread
- {
- private int tick=100;
- public void run()
- {
- while(true)
- {
- if(tick>0)
- {
- System.out.println(Thread.currentThread().getName()+"tick+"+tick--);
- }
- }
- }
- }
- class Demo2
- {
- public static void main(String[] args)
- {
- Ticket t=new Ticket();
- Thread t1=new Thread(t);
- Thread t2=new Thread(t);
- Thread t3=new Thread(t);
- Thread t4=new Thread(t);
- t1.start();
- t2.start();
- t3.start();
- t4.start();
- /*Ticket t1=new Ticket();
- Ticket t2=new Ticket();
- Ticket t3=new Ticket();
- Ticket t4=new Ticket();
- t1.start();
- t2.start();
- t3.start();
- t4.start();
- */
- }
- }
复制代码
|
|