- class Ticket implements Runnable
- {
- private int tick = 1000;
- Object obj = new Object();
- public void run()
- {
- while(true)
- {
- synchronized(obj)
- {
- if(tick>0)
- {
- System.out.println(Thread.currentThread().getName()+"....sale : "+ tick--);
- }
- }
- }
- }
- }
复制代码 Object obj = new Object(); 进程同步这里的obj是什么?什么作用
|