标签:
synchronized(this){ //java code; }
Object o = new Object(); synchronized(o){ //java code; }
public synchronized void set(){ while(storage.size()==maxSize){ try{ wait(); }catch(InterruptedException e){ e.printStackTrace(); } } }
private ReadWriteLock lock = new ReadWriteLock (); //获取读操作锁 lock.readLock().lock(); //释放读操作锁 lock.readLock().unlock(); //获取写操作锁 lock.writeLock().lock(); //释放写操作锁 lock.writeLock().unlock();
ReentrantLock Lock = new ReentrantLock(); Condition line = lock.newCondition(); Condition space = lock.newCondition(); while(buffer.size()==maxSize){ space.await(); } line.signalAll(); while(buffer.size()==0){ line.await(); } space.signalAll();
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/jiaomingliang/article/details/47340139