-
Notifications
You must be signed in to change notification settings - Fork 36
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
MemberToMetricMappings should be thread-safe #444
Comments
Do we actually use it from multiple threads (for modification) somewhere? Because populating this map is a thing that happens at build time (startup time in JVM) by iterating through available annotations. I think neither Quarkus nor the portable CDI extension (which is used in WildFly) use multiple threads for this, am I mistaken? |
Well, the question is whether it can be used from multiple threads... Another point is that those structures do not ensure safe propagation, i.e. the changes may not be visible from other threads. |
Better be safe than sorry ;-) |
If we don't plan modifying this in multiple threads, then synchronizing comes with an unnecessary performance penalty, in which case I think we should just make it more clear (in Javadoc) that modifying in multiple threads is forbidden?!
(And similarly for No objection to making the fields |
I think that this penalty would be negligible but it's ok to clarify the contract in the javadoc too. It might make also sense to optimize the structures after the mappings are intialized, e.g. use some immutable structures. And speaking of performance - the interceptors could reuse a |
Because it can be used from multiple threads.
io.smallrye.metrics.MemberToMetricMappings.counters
and others should befinal
andConcurrentMap
. The same applies to the values - these should be synchronized as well (e.g. viaCopyOnWriteArraySet
orCollections.synchronizedSet()
).The text was updated successfully, but these errors were encountered: