File tree Expand file tree Collapse file tree 2 files changed +4
-20
lines changed
main/java/org/elasticsearch/common/util/concurrent
test/java/org/elasticsearch/common/util/concurrent Expand file tree Collapse file tree 2 files changed +4
-20
lines changed Original file line number Diff line number Diff line change 26
26
public final class KeyedLock <T > {
27
27
28
28
private final ConcurrentMap <T , KeyLock > map = ConcurrentCollections .newConcurrentMapWithAggressiveConcurrency ();
29
- private final boolean fair ;
30
-
31
- /**
32
- * Creates a new lock
33
- * @param fair Use fair locking, ie threads get the lock in the order they requested it
34
- */
35
- public KeyedLock (boolean fair ) {
36
- this .fair = fair ;
37
- }
38
-
39
- /**
40
- * Creates a non-fair lock
41
- */
42
- public KeyedLock () {
43
- this (false );
44
- }
45
29
46
30
/**
47
31
* Acquires a lock for the given key. The key is compared by it's equals method not by object identity. The lock can be acquired
@@ -90,7 +74,7 @@ public Releasable tryAcquire(T key) {
90
74
}
91
75
92
76
private ReleasableLock tryCreateNewLock (T key ) {
93
- KeyLock newLock = new KeyLock (fair );
77
+ KeyLock newLock = new KeyLock ();
94
78
newLock .lock ();
95
79
KeyLock keyLock = map .putIfAbsent (key , newLock );
96
80
if (keyLock == null ) {
@@ -140,8 +124,8 @@ public void close() {
140
124
141
125
@ SuppressWarnings ("serial" )
142
126
private static final class KeyLock extends ReentrantLock {
143
- KeyLock (boolean fair ) {
144
- super (fair );
127
+ KeyLock () {
128
+ super ();
145
129
}
146
130
147
131
private final AtomicInteger count = new AtomicInteger (1 );
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public class KeyedLockTests extends ESTestCase {
29
29
public void testIfMapEmptyAfterLotsOfAcquireAndReleases () throws InterruptedException {
30
30
ConcurrentHashMap <String , Integer > counter = new ConcurrentHashMap <>();
31
31
ConcurrentHashMap <String , AtomicInteger > safeCounter = new ConcurrentHashMap <>();
32
- KeyedLock <String > connectionLock = new KeyedLock <>(randomBoolean () );
32
+ KeyedLock <String > connectionLock = new KeyedLock <>();
33
33
String [] names = new String [randomIntBetween (1 , 40 )];
34
34
for (int i = 0 ; i < names .length ; i ++) {
35
35
names [i ] = randomRealisticUnicodeOfLengthBetween (10 , 20 );
You can’t perform that action at this time.
0 commit comments