Modifying Lock fairness

The constructor of the ReentrantLock and ReentrantReadWriteLock classes admits a boolean parameter named fair that allows you to control the behavior of both classes. The false value is the default value and it's called the non-fair mode . In this mode, when there are some threads waiting for a lock (ReentrantLock or ReentrantReadWriteLock) and the lock has to select one of them to get the access to the critical section, it selects one without any criteria. The true value is called the fair mode. In this mode, when there are some threads waiting for a lock (ReentrantLock or ReentrantReadWriteLock) and the lock has to select one to get access to a critical section, it selects the thread that has been waiting for the most ...

Get Java 7 Concurrency Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.