What is the relationship between number of CPU cores and number of threads in an app in java?

后端 未结 7 891
臣服心动
臣服心动 2021-01-31 00:07

I\'m new to java multi-threaded programming. The question that has came to my mind is that how many threads can I run according to the number of my CPU

7条回答
  •  無奈伤痛
    2021-01-31 00:36

    Idea behind it is don't let your CPU sleep, neither load it too much that it waste most of time in thread switching.

    Its helpful to check Tuning the pool size, In IBMs paper

    Idea behind is, it depends on the nature of task, if its all in-memory computation tasks you can use N+1 threads (N numbers of cores (included hyper threading)).

    Or

    we need to do the application profiling and find out waiting time (WT) , service time (ST) for a typical request and approximately N*(1+WT/ST) number of optimal threads we can have, considering 100% utilization of CPU.

提交回复
热议问题