gnodet opened a new pull request, #24349:
URL: https://github.com/apache/camel/pull/24349
## Summary
_Claude Code on behalf of Guillaume Nodet_
Fixes `ConcurrentModificationException` in TUI `MemoryTab.renderSparkline()`
caused by a race condition between the background data-refresh thread and the
UI render thread.
**Root cause**: `MetricsCollector` stores history data as `LinkedList`
values inside `ConcurrentHashMap` maps. The background refresh thread mutates
these lists in place (`.add()`, `.remove(0)`), while the UI render thread
iterates them via `.stream()` and `.get(i)`. `ConcurrentHashMap` protects the
map itself but not the individual `LinkedList` values.
**Fix**: Use copy-on-write semantics in `MetricsCollector` — instead of
mutating history lists in place, create a new copy, modify it, and atomically
swap it into the map via `ConcurrentHashMap.compute()`. Readers always iterate
an unmodified list snapshot. This fixes **all** affected tabs at once
(MemoryTab, OverviewTab, EndpointsTab, CircuitBreakerTab).
- Introduce `addToHistory()` helper that encapsulates the copy-on-write
pattern
- Refactor all 8 history update sites in `MetricsCollector` to use it
- Add concurrency regression tests exercising concurrent read/write
**Stack trace that was observed:**
```
java.util.ConcurrentModificationException
at
java.base/java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1254)
at
java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
...
at
org.apache.camel.dsl.jbang.core.commands.tui.MemoryTab.renderSparkline(MemoryTab.java:244)
at
org.apache.camel.dsl.jbang.core.commands.tui.MemoryTab.render(MemoryTab.java:116)
```
## Test plan
- [x] New `MetricsCollectorConcurrencyTest` with 2 tests exercising
concurrent read/write on heap and throughput history maps
- [x] All 469 existing TUI tests pass
- [ ] Manual verification: run `camel monitor` with a live integration and
navigate to the Memory tab
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]