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

Creating multiple instances #7

Open
pkriens opened this issue Sep 1, 2017 · 0 comments
Open

Creating multiple instances #7

pkriens opened this issue Sep 1, 2017 · 0 comments

Comments

@pkriens
Copy link

pkriens commented Sep 1, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant