You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, these classes are not concurrent, they are synchronized.
Concurrent classes allows scaling and would actually allow multiple threads to make changes to the same collection. This is made possible by not synchronizing on the whole collection, but on individual "buckets" inside the collection.
Synchronized classes does not scale and only allows one thread to make changes.
I would recommend to clarify this by changing the names (although that would be a breaking change, so maybe use a deprecated typealias to support backwards compatibility) and adding to the readme that the collections use synchronization on a single object to make them thread-safe, and that they are not concurrent.
An even better solution would however of course be to make the collections properly concurrent.
I was looking for a replacement for Java's
ConcurrentHashMap
in Kotlin and stumbled upon this library.When reading the code https://github.com/touchlab/Stately/tree/main/stately-concurrent-collections/src/commonMain/kotlin/co/touchlab/stately/collections I was a bit disappointed and would like the repository to clarify a few things or improve things.
Currently, these classes are not concurrent, they are synchronized.
Concurrent classes allows scaling and would actually allow multiple threads to make changes to the same collection. This is made possible by not synchronizing on the whole collection, but on individual "buckets" inside the collection.
Synchronized classes does not scale and only allows one thread to make changes.
I would recommend to clarify this by changing the names (although that would be a breaking change, so maybe use a deprecated typealias to support backwards compatibility) and adding to the readme that the collections use synchronization on a single object to make them thread-safe, and that they are not concurrent.
An even better solution would however of course be to make the collections properly concurrent.
For more information, see e.g. https://javarevisited.blogspot.com/2016/05/what-is-difference-between-synchronized.html#axzz8dav8KUva and https://www.baeldung.com/java-synchronizedmap-vs-concurrenthashmap
The text was updated successfully, but these errors were encountered: