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.
This discussion was converted from issue #112 on July 31, 2026 19:21.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I was looking for a replacement for Java's
ConcurrentHashMapin 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
All reactions