Skip to content

Conversation

@petruki
Copy link
Member

@petruki petruki commented Oct 15, 2025

This pull request refactors how history execution is managed in the SwitcherBuilder and its concrete implementation SwitcherRequest, improves thread safety, and simplifies null checks across the codebase. The main theme is to make the history execution logic more robust and concurrent, while also standardizing null checks using Objects.nonNull and Objects.isNull.

History Execution Refactor

  • Moved the historyExecution map from the abstract SwitcherBuilder to the concrete SwitcherRequest class, and changed its implementation from a regular HashMap to a thread-safe ConcurrentHashMap for better concurrency support. ([[1]](https://github.com/switcherapi/switcher-client-java/pull/381/files#diff-ac0544cec82f9e6e850d4929bf6edf6ba3397237b1bba0012f503cba484971e7L19-L20), [[2]](https://github.com/switcherapi/switcher-client-java/pull/381/files#diff-50b643c046fcf01d65f95fbeb497f0da0daaf755828ef185e1a3bd8381b2b710R27-R28), [[3]](https://github.com/switcherapi/switcher-client-java/pull/381/files#diff-50b643c046fcf01d65f95fbeb497f0da0daaf755828ef185e1a3bd8381b2b710R48))
  • Changed the flush method in SwitcherBuilder to be abstract, with SwitcherRequest now implementing it to clear both entry and historyExecution. ([[1]](https://github.com/switcherapi/switcher-client-java/pull/381/files#diff-ac0544cec82f9e6e850d4929bf6edf6ba3397237b1bba0012f503cba484971e7L45-R42), [[2]](https://github.com/switcherapi/switcher-client-java/pull/381/files#diff-50b643c046fcf01d65f95fbeb497f0da0daaf755828ef185e1a3bd8381b2b710R72-R78))

Thread Safety and Synchronization

  • Removed the synchronized keyword from the execute method in AsyncSwitcher, potentially improving performance and relying on the thread safety of the underlying data structures. ([src/main/java/com/switcherapi/client/model/AsyncSwitcher.javaL49-R49](https://github.com/switcherapi/switcher-client-java/pull/381/files#diff-c4e53fc6b375fc5ce77e080aa254d0321fef50ebdb25a7ccf460bbf9a2c4041dL49-R49))

[Before] Operations /s in 5s

Benchmark Type Mode Score Units
ClientJavaBenchmark.testSwitcherRemoteThrottle Async thrpt 40,171,215.842 ops/s
ClientJavaBenchmark.testSwitcherLocal Local thrpt 19,689,072.262 ops/s

[After] Operations /s in 5s

Benchmark Type Mode Score Units
ClientJavaBenchmark.testSwitcherRemoteThrottle Async thrpt 109,325,445.942 ops/s
ClientJavaBenchmark.testSwitcherLocal Local thrpt 41,501,007.578 ops/s

@petruki petruki added this to the v2.5.2 milestone Oct 15, 2025
@petruki petruki self-assigned this Oct 15, 2025
@petruki petruki added the enhancement New feature or request label Oct 15, 2025
@sonarqubecloud
Copy link

@petruki petruki merged commit 0ba056e into master-2 Oct 15, 2025
9 checks passed
@petruki petruki deleted the staging branch October 15, 2025 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants