Skip to content

Commit 8643600

Browse files
committed
Reduce contention in TypeNameIdResolver. Fixes [FasterXML#2556]
1 parent c1250b7 commit 8643600

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fasterxml.jackson.databind.jsontype.impl;
22

33
import java.util.*;
4+
import java.util.concurrent.ConcurrentHashMap;
45

56
import com.fasterxml.jackson.annotation.JsonTypeInfo;
67
import com.fasterxml.jackson.databind.BeanDescription;
@@ -28,8 +29,8 @@ protected TypeNameIdResolver(MapperConfig<?> config, JavaType baseType,
2829
{
2930
super(baseType, config.getTypeFactory());
3031
_config = config;
31-
_typeToId = typeToId;
32-
_idToType = idToType;
32+
_typeToId = new ConcurrentHashMap<String, String>(typeToId);
33+
_idToType = new ConcurrentHashMap<String, JavaType>(idToType);
3334
}
3435

3536
public static TypeNameIdResolver construct(MapperConfig<?> config, JavaType baseType,
@@ -91,10 +92,7 @@ protected String idFromClass(Class<?> clazz)
9192
// NOTE: although we may need to let `TypeModifier` change actual type to use
9293
// for id, we can use original type as key for more efficient lookup:
9394
final String key = clazz.getName();
94-
String name;
95-
synchronized (_typeToId) {
96-
name = _typeToId.get(key);
97-
}
95+
String name = _typeToId.get(key);
9896

9997
if (name == null) {
10098
// 29-Nov-2019, tatu: As per test in `TestTypeModifierNameResolution` somehow
@@ -110,9 +108,7 @@ protected String idFromClass(Class<?> clazz)
110108
// And if still not found, let's choose default?
111109
name = _defaultTypeId(cls);
112110
}
113-
synchronized (_typeToId) {
114-
_typeToId.put(key, name);
115-
}
111+
_typeToId.put(key, name);
116112
}
117113
return name;
118114
}

0 commit comments

Comments
 (0)