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

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

    The number of threads a system can execute simultaneously is (of course) identical to the number of cores in the system.

    The number of threads that can exist on the system is limited by the available memory (each thread requires a stack and a structure used by the OS to manage the thread), and possibly there is a limitation how many threads the OS allows (this depends on the OS architecture, some OS' may use a fixed size table and once its full no more threads can be created).

    Commonly, todays computers can handle hundreds to thousands of threads.

    The reason why more threads are used than cores exist in the system is: Most threads will inevitably spend much of their time waiting for some event (example: word processor waiting for user to type on keyboard). The OS manages it that threads that wait in such a manner do not consume CPU time.

    0 讨论(0)
提交回复
热议问题