Skip to content

Signed-off-by: Dileep Kumar Somajohassula dileepharithasa@gmail.com - Replace HashMap with ConcurrentHashMap for producer and consumer#3200

Open
dileepharithasa wants to merge 1 commit into
spring-cloud:mainfrom
dileepharithasa:fix/non-thread-safe-binding-registries
Open

Signed-off-by: Dileep Kumar Somajohassula dileepharithasa@gmail.com - Replace HashMap with ConcurrentHashMap for producer and consumer#3200
dileepharithasa wants to merge 1 commit into
spring-cloud:mainfrom
dileepharithasa:fix/non-thread-safe-binding-registries

Conversation

@dileepharithasa

@dileepharithasa dileepharithasa commented Jun 13, 2026

Copy link
Copy Markdown

Signed-off-by: Dileep Kumar Somajohassula dileepharithasa@gmail.com -binding registries, and use CopyOnWriteArrayList for consumer binding lists to prevent concurrent modification issues during bind, unbind operations and concurrent iteration.

binding registries, and use CopyOnWriteArrayList for consumer
binding lists to prevent concurrent modification issues during
bind, unbind operations and concurrent iteration.
@dileepharithasa dileepharithasa changed the title Replace HashMap with ConcurrentHashMap for producer and consumer Signed-off-by: Dileep Kumar Somajohassula dileepharithasa@gmail.com - Replace HashMap with ConcurrentHashMap for producer and consumer Jun 14, 2026
@dileepharithasa

Copy link
Copy Markdown
Author

Hello @olegz and team,

Could you please review this PR when you have a chance?

This change makes the BindingService registries thread-safe by replacing HashMap with ConcurrentHashMap and using CopyOnWriteArrayList for consumer binding lists.

Thank you!

@dileepharithasa

Copy link
Copy Markdown
Author

Hello @olegz and team,

Could you please review this PR when you have a chance?

Thanks

@olegz

olegz commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Unfortunately ConcurrentHashMap presents a significant performance degradation

@dileepharithasa

Copy link
Copy Markdown
Author

Unfortunately ConcurrentHashMap presents a significant performance degradation

Thanks for the feedback.

Could you provide more details on the performance concerns with ConcurrentHashMap in this context?

  1. Compared to what baseline or benchmark?
  2. Under what workload characteristics (read-heavy, write-heavy, binding churn, etc.)?
  3. Approximately how many bindings are expected to be present?
  4. Do we have any throughput or latency measurements demonstrating a noticeable impact?
  5. Is this registry known to be on a performance-critical execution path?

The proposed solution:
Uses ConcurrentHashMap to provide thread-safe access to the producer and consumer binding registries.
Uses CopyOnWriteArrayList for consumer bindings to allow safe iteration while updates occur concurrently.
Preserves the existing behavior and API contract while improving concurrency guarantees.

My understanding is that these binding registries are relatively small and are accessed concurrently by multiple threads. In this case, correctness and thread safety would seem more important than the relatively small overhead introduced by ConcurrentHashMap. Unless there is profiling or benchmark data showing a measurable regression in this specific scenario, it may be difficult to assess the significance of the performance concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants