Some threads in Java ForkJoinPool become idle once in a while

Viewed 267

I've a Java code like below:

Stream<String> stream = getStreamFromSomewhere()
ForkJoinPool pool = new ForkJoinPool(32);
pool.submit(() -> stream.parallel()
                        .filter(condition)
                        .forEach(x -> recursive(x))).get();
pool.shutdown();

Now this code runs quick enough, using all 32 threads in my machine, each utilized at around 70-80%.

Oddly, after every few mins or so, the CPU util of all threads go down to 0% except 2 threads (or sometimes 1) which goes up to 100%. A minute or so later, it would be alright with all of them humming along at 70-80% again. This behavior repeats every few mins or so.

I'm unable to pinpoint what could cause this. Any ideas would be helpful.

2 Answers
Related