KITFORMA · EDITORIAL ANSWER
Why does parallelStream lose results when each worker adds to one ArrayList?
KitForma editorial guide. The shared accumulator has become a concurrent mutable resource. A sequential test can hide that ownership error.
Step-by-step answer
rows.parallelStream().map(this::transform).collect(Collectors.toList()) when transformation is independent and the collector owns accumulation. If transformation touches a shared cache, database session or formatter, fix that state separately; a collector only protects its own collection strategy. Use a sequential pipeline when there is no measured benefit from parallel work.
Compare exact identifiers and counts against a sequential reference on repeated synthetic runs. Do not rely on one successful stress test as proof of thread safety. Ordered result collection does not guarantee that side effects inside transform happened in the same order.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.