Java ReentrantLock isFair() MethodThe isFair() method of ReentrantLock class returns true if the fairness to acquire this lock is true. SyntaxParameterthread - the thread Returnstrue if this lock has fairness set true ThrowsNo exception is thrown Example 1Test it NowOutput: 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 2Test it NowOutput: 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
|