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

前端 未结 4 1985
萌比男神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:41

    While all the other answers have explained how you can theoretically have thousands of threads in your application at the cost of memory and other overheads already well explained here. It is however worth noting that the default concurrencyLevel for the data structures provided in the java.util.concurrent package is 16.

    You will come across contention issues if you don't account for the same.

    Using a significantly higher value than you need can waste space and time, and a significantly lower value can lead to thread contention.

    Make sure you have set the appropriate concurrencyLevel in case you are running into issues related to concurrency with a higher number of threads.

提交回复
热议问题