avandecreme
avandecreme

Reputation: 979

ForkJoinPool using more CPU than specified

I set up a ForkJoinPool to use half of my CPUs like this:

ForkJoinPool forkJoinPool = new ForkJoinPool(
        Runtime.getRuntime().availableProcessors() / 2);

However, when I submit a job such as the merge sort described there, the pool is using up to 80+% of my machine CPUs.

Is this something expected? If so, is there a way to effectively restrict the number of working threads?

Upvotes: 0

Views: 1378

Answers (1)

edharned
edharned

Reputation: 1904

The excessive thread problem goes back to early Java7. You did not specify which version you're using, but no matter, both Java7 and Java8 have similar problems with excessive threads. Java8u40 addressed some of the excessive problems in nested calls, but at the expense of excessive spinning.

I've been writing a continuing critique of this framework since 2011. The article for Java8 is here There are links to both the first (Java7) and 8u40 articles therein.

To specifically answer your question: There is no way to restrict the use of work threads with this framework.

Upvotes: 1

Related Questions