1 |
dl |
1.1 |
/* |
2 |
|
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
|
* Expert Group and released to the public domain. Use, modify, and |
4 |
|
|
* redistribute this code in any way without acknowledgement. |
5 |
|
|
*/ |
6 |
|
|
|
7 |
|
|
package java.util.concurrent; |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* A reentrant mutual exclusion lock that, under contention, favors |
11 |
|
|
* granting access to the longest-waiting thread. Programs using fair |
12 |
|
|
* locks may display lower overall throughput (i.e., are slower) than |
13 |
|
|
* those using default locks, but have but smaller variances in times |
14 |
|
|
* to obtain locks. |
15 |
dl |
1.2 |
* @since 1.5 |
16 |
|
|
* @author Doug Lea |
17 |
dl |
1.1 |
*/ |
18 |
|
|
|
19 |
|
|
public class FairReentrantLock extends ReentrantLock { |
20 |
|
|
/** |
21 |
|
|
* Creates an instance of <tt>FairReentrantLock</tt>. |
22 |
|
|
*/ |
23 |
|
|
public FairReentrantLock() { } |
24 |
|
|
|
25 |
|
|
/** |
26 |
|
|
* Return true if it is OK to take fast path to lock. For fair |
27 |
|
|
* locks, we allow barging only when there are no waiters. |
28 |
dl |
1.2 |
* @return true if queue empty |
29 |
dl |
1.1 |
*/ |
30 |
|
|
boolean canBarge() { |
31 |
|
|
return queueEmpty(); |
32 |
|
|
} |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|