`
ruruhuang
  • 浏览: 189342 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Read/Write Lock

阅读更多
public class SomeContainer { private Set<element> elements; private ReadWriteLock globalLock; private Lock readLock; private Lock writeLock; SomeContainer() {  elements = new HashSet<element>();  globalLock = new ReentrantReadWriteLock();  readLock = globalLock.readLock();  writeLock = globalLock.writeLock(); }  public void addElement(Element elem) {  writeLock.lock();  try {   elements.add(elem);  }  finally {   writeLock.unlock();  }  }  public void processElements(ElementProcessor processor) {  readLock.lock();  try {   Iterator<element> iter = elements.iterator();    while(iter.hasNext()) {     Element element = iter.next();     processor.processElement(element);  }  finally {   readLock.unlock(); }  // ... }interface ElementProcessor { void processElement(Element element);}

So, in the example above, the first line in processElements will let everybody play at once so long as the write lock is not held. Then, when the write lock is requested, the requesting thread will be made to wait until all existing readers are done (no further readers will be let in), and then the writer thread may begin.

 

http://www.javalobby.com/java/forums/t45090.html

分享到:
评论

相关推荐

    linux下实现高性能读写锁(read/write lock)

    在linux下按照windows的slim read/write lock算法实现的读写锁源码。

    share_mem.tar.gz

    linux下实现高性能读写锁(read/write lock) 附带makefile,工程模板

    Pthreads APIs - User's Guide and Reference

    Read/write lock synchronization APIs Signals APIs What are Pthreads? Primitive data types for Pthreads Feature test macros for Pthreads OS/400 Pthreads versus the POSIX standard, the Single UNIX...

    read-write-lock:读与写互斥,写与所有事物互斥

    var createMutex = require ( 'read-write-lock' ) var mutex = createMutex ( ) mutex . writeLock ( function ( release ) { // lol I've got a write lock which means that nobody else can do anything ...

    ReadWriteLock

    一个Windows下C++读写锁的代码,实现共享读,独占写

    An Overview of Linux Kernel Locking Improvements (August 2014)-计算机科学

    The information contained herein is subject to change without notice.An Overview of Kernel Lock ImprovementsDavidlohr Bueso & Scott NortonLinuxCon North... Read/write semaphores6. Read/write [spin]locks

    rwlock:Haxe 的读写锁

    读写锁 ... 仅在定义了 READ_WRITE_LOCK_SUPER 时才公开。 表现 定义: 首先,让我们创建一些对象: k: a lock R: number of readers W: number of writers 为简单起见,假设我们有 1 个操作/读取器和

    Java并发:基础线程同步

    In this chapter, we will cover: 1.Synchronizing a method; 2.Arranging independent ... 5.Synchronizing data access with read/write locks 6.Modifying Lock fairness 7.Using multiple conditions in a Lock

    open file view

    For each opened file, additional information is displayed: handle value, read/write/delete access, file position, the process that opened the file, and more... Optionally, you can also close one or ...

    Yii+MYSQL锁表防止并发情况下重复数据的方法

    lock tables user read;//读锁定表 unlock tables;//解锁 lock tables user read local;//本地读锁定表,其他线程的insert未被阻塞,update操作被阻塞 lock table 写锁定 如果一个线程在一个表上得到一个 write锁,...

    pcf8563_i2c1_r8_ruoge_ov2640通过给RTC驱动增加设备节点读取秒钟成功+直接读取I2C1获取秒钟值20160626_2201.7z

    int i2c_read_reg(char *dev, unsigned char *buf, unsigned slave_address, unsigned reg_address, int len) { struct i2c_rdwr_ioctl_data work_queue; unsigned char w_val = reg_address; int ret; ...

    ATmega16A.rar_EEPROM_READ_avr_operation

    High-performance, Low-power Atmel AVR 8-bit Microcontroller &#1048698 Advanced RISC Architecture ...&#1048698 True Read-While-Write Operation &#822 Programming Lock for Software Security

    ATmega8515 datasheet.pdf

    True Read-While-Write Operation – 512 Bytes EEPROM Endurance: 100,000 Write/Erase Cycles – 512 Bytes Internal SRAM – Up to 64K Bytes Optional External Memory Space – Programming Lock for Software ...

    微软内部资料-SQL性能优化3

     Discuss how lock manager uses lock mode, lock resources, and lock compatibility to achieve transaction isolation.  Describe the various transaction types and how transactions differ from batches....

    MySerialPort.js工具类

    read---port.readable.getReader()的读取字节数组方法 write---port.writable.getWriter()的写入方法 ———————————————— 版权声明:本文为CSDN博主「ZhangY1217」的原创文章,遵循CC 4.0 BY-SA版权...

    java多线程设计模式 (PDF中文版, 附源码)

    第6章 Read-Write Lock——大家想看就看吧,不过看的时候不能写喔 第7章 read-Per-Message——这个工作交给你了 第8章 Worker Thread——等到工作来,来了就工作 第9章 Future——先给您这张提货单 第10章 Two-Phase...

    MySQL数据库:锁定与解锁.pptx

    数据库编程 锁定与解锁 课程目标 了解 —— 锁定和解锁的概念; 掌握 —— 锁定和解锁的设置; 锁定与解锁 MySQL提供了LOCK TABLES语句来锁定当前线程的表,语法格式如下: ...LOCK TABLES XS READ; 说明:LOCK TABLE

    Java多线程详解

    6、Read-Write Lock ———— 大家想看就看吧,不过看的时候不能写哦 7、Thread-Per-Message ———— 这个工作交给你了 8、Worker Thread ———— 等到工作来,来了就工作 9、Future ———— 先给您这张提货单 10...

    cdma 读取数据强器

    轻松读取数据,更改esn,meid Unlock spc, MSL, SPC3, FSK, OTKSL, User Lock, MIN lock, SIM LOCK Programming: MIN, MDN, IMSI, NAM, PRL file, Phone Settings ... Read Write EEPROM, RAM, SDRAM area)

    嵌入式的多线程应用程序设计

    if (b-&gt;writepos &gt;= BUFFER_SIZE) b-&gt;writepos = 0; /* Signal that the buffer is now not empty */ pthread_cond_signal(&b-&gt;notempty); pthread_mutex_unlock(&b-&gt;lock); } /*---------------------------...

Global site tag (gtag.js) - Google Analytics