Parallel stream blocks common pool

On-call incidentHard40 min

Your task

A Java service handles most requests fine, but a subset of requests that fan out work using list.parallelStream()... intermittently hang for many seconds across the WHOLE service, even simple requests that don't use parallel streams slow down at the same time. CPU is moderate. A thread dump shows the JVM's ForkJoinPool.commonPool worker threads all parked/blocked inside network or DB calls. A recent change added a blocking remote call inside the lambda passed to a parallelStream(). How do you triage and mitigate?

It covers

  • Thread pool exhaustion
  • Forkjoinpool
  • Parallel streams