Sequential Async Join in Loop¶
Rule details
| Rule ID | sequential-async-join-in-loop |
| Severity | WARNING — likely performance problem |
| Confidence | HIGH — structurally proven |
| Category | Loop amplifiers |
| Complexity | O(n·wait) → O(max-wait) |
Description¶
Detects blocking calls (.join(), .get()) on futures inside loops. Awaiting each future sequentially negates the benefit of async execution — the total wall time becomes the sum of all individual waits instead of the maximum.
Typical¶
After¶
Use Promise.all to await all promises concurrently:
How Detection Works¶
- Identifies loop constructs
- Inside each loop, looks for blocking calls (
.join(),.get()) - Checks that the target variable name suggests a future or promise (
future,promise,async,completable,deferred,task)
Suggestion¶
Collect all futures first, then call .join()/.get() outside the loop (e.g. CompletableFuture.allOf)