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

后端 未结 7 925
臣服心动
臣服心动 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:39

    Having less threads than CPUs can mean you are not using all the CPUs in your system. Having more threads might improve throughput if CPU is your bottleneck.

    Having more threads than CPU does introduce an overhead and if CPU is your bottleneck this can hurt performance. However, if network IO, is your bottleneck, this overhead is a price worth paying as it usually allows you to handle many more connections. e.g. You can have 1000 TCP connections with their own threads.

提交回复
热议问题