Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-15960: Use ConcurrentHashMap for EnvUtils.camelCaseToDotsMap #2204

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Changes from all 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
14 changes: 5 additions & 9 deletions solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.solr.common.SolrException;

Expand All @@ -40,7 +41,7 @@
public class EnvUtils {
private static final SortedMap<String, String> ENV = new TreeMap<>(System.getenv());
private static final Map<String, String> CUSTOM_MAPPINGS = new HashMap<>();
private static final Map<String, String> camelCaseToDotsMap = new HashMap<>();
private static final Map<String, String> camelCaseToDotsMap = new ConcurrentHashMap<>();

static {
try {
Expand Down Expand Up @@ -171,14 +172,9 @@ private static String getPropWithCamelCaseFallback(String key) {
}

private static String camelCaseToDotSeparated(String key) {
if (camelCaseToDotsMap.containsKey(key)) {
return camelCaseToDotsMap.get(key);
} else {
String converted =
String.join(".", key.split("(?=[A-Z])")).replace("..", ".").toLowerCase(Locale.ROOT);
camelCaseToDotsMap.put(key, converted);
return converted;
}
return camelCaseToDotsMap.computeIfAbsent(
key,
(k) -> String.join(".", k.split("(?=[A-Z])")).replace("..", ".").toLowerCase(Locale.ROOT));
}

/** Get property as integer */
Expand Down
Loading