What do we understand by fair locks?

By | September 22, 2019

In this blog post we will talk and learn about one of very important multi Threading Java interview question and question is that What do we understand by fair locks?

  • A fair lock takes the waiting time of the threads into account when choosing the next thread that passes the barrier to some exclusive resource.
  • An example implementation of a fair lock is provided by the Java is:java.util.concurrent.locks.ReentrantLock.
  • If the constructor with the boolean flag set to true is used, the ReentrantLock grants access to the longest-waiting thread.

Let’s try to understand using an Example..

Output

That’s all about  What do we understand by fair locks?
If you have any feedback or suggestion please feel free to drop in blow comment box.

Leave a Reply

Your email address will not be published.