Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.core.util;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

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

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

Expand All @@ -51,10 +52,13 @@ public String intern(String input) {
* storage gives close enough answer to real one here; and we are
* more concerned with flooding than starvation.
*/
synchronized (lock) {
lock.lock();
try {
if (size() >= MAX_ENTRIES) {
clear();
}
} finally {
lock.unlock();
}
}
result = input.intern();
Expand Down