The number of thread pools allocated in java concurrent programming is related to CPU-intensive tasks and I/O-intensive tasks

CPU-intensive tasks : The application mainly uses a lot of CPU resources to perform non-blocking logical operations, so it is necessary to avoid excessive thread context switching. Therefore, the range of the number of threads is: the
number of threads = the number of CPU cores + 1
can also be set to the number of CPU cores * 2, which depends on the version of the JDK used and the CPU configuration (the server's CPU has hyperthreading). For JDK1.8, a parallel calculation has been added. The ideal number of computing-intensive threads = the number of CPU kernel threads * 2
IO-intensive tasks : it takes more CPU time than IO operations than CPU computing operations. said. For example, most web application development will involve a lot of network transmission; not only that, but the interaction with the database or cache also involves IO. Once IO occurs, the thread will be in a waiting state, so we can slightly set the number of threads in the thread pool, so that the thread can do other things during the period of waiting for IO, and improve the efficiency of concurrent processing .
The range of the number of threads in the thread pool is: number of
threads = number of CPU cores/(1-blocking coefficient)
    This blocking coefficient is generally between 0.8 and 0.9, or 0.8 or 0.9. The above is not absolute and needs to be adjusted according to the actual situation and actual business.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326053774&siteId=291194637