02 February 2009

Java Performance Tuning comments on ReadWriteLocks

Tips December 2008
http://www.javaspecialists.eu/archive/Issue165.html
Starvation with ReadWriteLocks (Page last updated October 2008, Added 2008-12-30, Author Dr. Heinz M. Kabutz, Publisher The Java Specialists' Newsletter). Tips:

* ReadWriteLock should only be used in cases where the critical section is at least 2000 code statements
* For most applications concurrency classes such as ConcurrentHashMap and ConcurrentLinkedQueue are more efficient than using ReadWriteLock.
* ReadWriteLock with many readers compared to writers can cause the write threads to be starved of access to the lock.
* Using fairness et to true in ReentrantLock reduces throughput significantly.
* You should probably never use ReadWriteLocks in Java 5. In Java 6, use ReadWriteLock when you are willing to wait for writers to get an opportunity to acquire the lock - they won't get locked out completely, but it might take some time before they are serviced.