Bruce Tate, author of “Bitter Java“, referred to my post on “Implementing Read-Write Locks in Java” in his book to explain the possible performance optimization one can achieve by using read-write locks instead of applying “synchronized” (Java’s mutex). However, it should be noted that blind application of read-write locks (rwlocks) can have its own penalty.
Performance improvement obtained from use of rwlocks is based on the assumption that “write” lock will be held infrequently and for a short duration.
Allowing reader threads to proceed in parallel. If the programmer becomes careless, and holds the write lock longer than he would had held a mutex, the performance may actually go deteriorate. This may not be intuitive at first but its something to be expected – since holding the write lock blocks reader threads as well, just like a mutex !



Discussion
No comments for “A Caveat To Using Read-Write Locks”