Skip to content

Commit e68a512

Browse files
committed
IntenCache - remove synchronized
1 parent b8a132e commit e68a512

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/com/fasterxml/jackson/core/util/InternCache.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fasterxml.jackson.core.util;
22

33
import java.util.concurrent.ConcurrentHashMap;
4+
import java.util.concurrent.locks.ReentrantLock;
45

56
/**
67
* Singleton class that adds a simple first-level cache in front of
@@ -29,7 +30,7 @@ public final class InternCache
2930
* cases where multiple threads might try to concurrently
3031
* flush the map.
3132
*/
32-
private final Object lock = new Object();
33+
private final ReentrantLock lock = new ReentrantLock();
3334

3435
public InternCache() { this(MAX_ENTRIES, 0.8f, 4); }
3536

@@ -51,10 +52,13 @@ public String intern(String input) {
5152
* storage gives close enough answer to real one here; and we are
5253
* more concerned with flooding than starvation.
5354
*/
54-
synchronized (lock) {
55+
lock.lock();
56+
try {
5557
if (size() >= MAX_ENTRIES) {
5658
clear();
5759
}
60+
} finally {
61+
lock.unlock();
5862
}
5963
}
6064
result = input.intern();

0 commit comments

Comments
 (0)