Skip to content

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

Closed

Description

@Zomis

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

Activity

  1. lukellmann commented on Jun 30, 2024

    @lukellmann

    this fact brings issues like #105

  2. locked and limited conversation to collaborators on Jul 31, 2026
  3. converted this issue into a discussion #120 on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions