`
macpaohui
  • 浏览: 10616 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

ReentrantReadWriteLock

 
阅读更多
创建ReentrantReadWriteLock对象
private ReentrantReadWriteLock rrw= new ReentrantReadWriteLock();

创建读锁和写锁:
private Lock readLock = rrw.readlock();
private Lock writeLock = rrw.writelock();

对写程序加锁:
public double set()
{
    writeLock.lock();
    try{  doSomething(); }
    finally{  writeLock.unlock();  }
}

对读程序加锁
public double set()
{
    readLock.lock();
    try{  doSomething();  }
    finally{ readLock.unlock();  }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics