O'Reilly logo

Java 7 Concurrency Cookbook by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required