|
private final Map<Contextual<?>, Instance> instances = new ConcurrentHashMap<>(); |
|
return (T) instances.computeIfAbsent(contextual, c -> new Instance<>(contextual, creationalContext)).get(); |
You are using a ConcurrentHashMap to maintain the instances. However, concurrent hash maps can call the lambda multiple times in an invocation. This means you create the object multiple times but loose the reference since only the last successful time is remembered.
microscoped/microscoped-core/src/main/java/org/tomitribe/microscoped/core/Scope.java
Line 27 in a6d8cc5
microscoped/microscoped-core/src/main/java/org/tomitribe/microscoped/core/Scope.java
Line 46 in a6d8cc5
You are using a ConcurrentHashMap to maintain the instances. However, concurrent hash maps can call the lambda multiple times in an invocation. This means you create the object multiple times but loose the reference since only the last successful time is remembered.