Cover by Javier Fernández González

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required