Код: Выделить всё
private static Map PATTERNS;
private static Map patterns() {
if (PATTERNS == null) {
PATTERNS = new WeakHashMap(); // ok? or should be synchronized?
}
return PATTERNS;
}
// intending to reuse those pre-compiled patters
private static Pattern pattern(final String regex) {
return patterns().computeIfAbsent(
requireNonNull(regex, "regex is null"), Pattern::compile);
}
Должны ли ШАБЛОНЫ быть синхронизированы в случае многопоточной среды?
Подробнее здесь: https://stackoverflow.com/questions/570 ... ap-harmful