Javatpoint Logo
Javatpoint Logo

Java ReentrantLock isFair() Method

The isFair() method of ReentrantLock class returns true if the fairness to acquire this lock is true.

Syntax

Parameter

thread - the thread

Returns

true if this lock has fairness set true

Throws

No exception is thrown

Example 1

Test it Now

Output:

task name is- Job1 outer lock  at 10:11:17 outer work
task name is- Job1 inner lock at 10:11:18 inner work
Lock Hold Count is - 2
Lock is Fair - false
task name - Job1 work done

Example 2

Test it Now

Output:

task name - Job2 waiting for lock
task name - Job1 outer lock  at 10:12:48  outer work
task name - Job2 waiting for lock
task name - Job1 inner lock acquired at 10:12:50 Doing inner work
Lock Hold Count - 2
task name - Job2 waiting for lock
task name - Job2 waiting for lock
task name - Job1 releasing lock (inner lock)
Lock Hold Count - 1
task name - Job1 work done
task name - Job1 releasing lock(outer lock)
Lock is Fair - false
task name - Job2 outer lock  at 10:12:52  outer work
task name - Job2 inner lock acquired at 10:12:54 Doing inner work
Lock Hold Count - 2
task name - Job2 releasing lock (inner lock)
Lock Hold Count - 1
task name - Job2 work done
task name - Job2 releasing lock(outer lock)
Lock is Fair - false
Next TopicJava ReentrantLock





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA