- class Tickit implements Runnable
- {
- private int tickit=100;
- Object o=new Object();
- public void run()
- {
- synchronized(o)
- {
- while(tickit>0)
- {
- try{Thread.sleep(1);}catch(Exception e){}
- System.out.println(Thread.currentThread().getName()+"卖票"+tickit--);
- }
- }
- }
- }
- class ThreadDemo1
- {
- public static void main(String[] args)
- {
- Tickit t=new Tickit();
- 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();
- }
- }
复制代码 运行结果,只有0线程运行,哪里出错了啊 |