Maximum number of threads than can run concurrently in java on a CPU

前端 未结 4 1982
萌比男神i
萌比男神i 2020-12-30 09:02

Please I got confused about something. What I know is that the maximum number of threads that can run concurrently on a normal CPU of a modern computer ranges from 8 to 16 t

4条回答
  •  囚心锁ツ
    2020-12-30 09:51

    Threads aren't tied to or limited by the number of available processors/cores. The operating system scheduler can switch back and forth between any number of threads on a single CPU. This is the meaning of "preemptive multitasking."

    Of course, if you have more threads than cores, not all threads will be executing simultaneously. Some will be on hold, waiting for a time slot.

    In practice, the number of threads you can have is limited by the scheduler - but that number is usually very high (thousands or more). It will vary from OS to OS and with individual versions.

    As far as how many threads are useful from a performance standpoint, as you said it depends on the number of available processors and on whether the task is IO or CPU bound. Experiment to find the optimal number and make it configurable if possible.

提交回复
热议问题