Closed stefanuhrig closed 2 years ago
Any suggestion or PR? @andi-huber, thoughts on that or an easy way to improve?
Well, a quick-fix would be switching from HashMap
to Hashtable
because Hashtable
is synchronized by default. I can prepare a PR if you like. However, I'm not very familiar with the project, and there might be other occurrences of static unsynchronized cache variables.
While the JDK may never seriously remove Hashtable, I guess a slightly cleaner approach could be one of those: https://crunchify.com/hashmap-vs-concurrenthashmap-vs-synchronizedmap-how-a-hashmap-can-be-synchronized-in-java/
ConcurrentHashMap
seems like a good choice to me because read operations won't block.
I've opened PR #372 for the issue.
I have merged a fix for Pi.
Thanks for fixing this so quickly!
Hi all,
If you have two threads and each thread has its own local
UnitConverter
instance, a concurrent call of#convert()
can lead to aConcurrentModificationException
because access to the staticCalculus$Pi#piCache
variable is not synchronized: https://github.com/unitsofmeasurement/indriya/blob/b8e58ca04913c858038217e7c32bc9d26798518f/src/main/java/tech/units/indriya/function/Calculus.java#L150This is a stack trace showing the issue:
If you have further questions on the issue, please reach out.
Cheers, Stefan