What determines the number of threads a Java ForkJoinPool creates?

前端 未结 5 1718
北恋
北恋 2020-12-02 11:00

As far as I had understood ForkJoinPool, that pool creates a fixed number of threads (default: number of cores) and will never create more threads (unless the a

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 11:39

    From the source comments:

    Compensating: Unless there are already enough live threads, method tryPreBlock() may create or re-activate a spare thread to compensate for blocked joiners until they unblock.

    I think what's happening is that you're not finishing any of the tasks very quickly, and since there aren't available worker threads when you submit a new task, a new thread gets created.

提交回复
热议问题