gnodet-bot commented on code in PR #31073:
URL: https://github.com/apache/camel/pull/31073#discussion_r4727596404


##########
core/camel-core/src/test/java/org/apache/camel/impl/DefaultEndpointRegistryTest.java:
##########
@@ -184,30 +186,44 @@ public void testConcurrency() throws InterruptedException 
{
         int nThreads = 4;
         ExecutorService executorService = 
Executors.newFixedThreadPool(nThreads);
         int iterations = 500;
+        AtomicReference<Throwable> failure = new AtomicReference<>();

Review Comment:
   `failure` is declared outside the `for (int j = 0; ...)` loop but is never 
reset between iterations. The current code is correct — when a worker throws, 
`failure.get()` is non-null after `await()` and the `AssertionError` aborts the 
test before the next iteration runs, so a stale value cannot be observed in a 
later iteration. But the placement requires tracing the abort path to verify 
this.
   
   Consider declaring `failure` inside the outer loop, alongside 
`allThreadCompletionSemaphore`:
   
   ```java
   for (int j = 0; j < iterations; j++) {
       CountDownLatch allThreadCompletionSemaphore = new 
CountDownLatch(nThreads);
       AtomicReference<Throwable> failure = new AtomicReference<>();
       for (int i = 0; i < nThreads; i++) {
   ```
   
   Each iteration then owns its `failure` reference independently — no 
reasoning about cross-iteration bleed required.



-- 
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]

Reply via email to