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

Concurrent and Synchronized are two different things: This is synchronized, not concurrent #112

Open
Zomis opened this issue Jun 19, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@Zomis
Copy link

Zomis commented Jun 19, 2024

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

@lukellmann
Copy link

this fact brings issues like #105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants