Add factory to create a NamedThreadLocal with an initial value

See gh-24705
This commit is contained in:
陈其苗
2020-03-16 13:48:52 +08:00
committed by Stephane Nicoll
parent b2a86cc42d
commit e1d0176faa
2 changed files with 41 additions and 9 deletions

View File

@@ -55,14 +55,7 @@ public class SimpleThreadScope implements Scope {
private static final Log logger = LogFactory.getLog(SimpleThreadScope.class);
private final ThreadLocal<Map<String, Object>> threadScope =
new NamedThreadLocal<>("SimpleThreadScope") {
@Override
protected Map<String, Object> initialValue() {
return new HashMap<>();
}
};
private final ThreadLocal<Map<String, Object>> threadScope = NamedThreadLocal.withInitial("SimpleThreadScope", HashMap::new);
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {