Understanding of CPU number, kernel number, thread number, Java multithreading relationship __java

Source: Internet
Author: User

the relationship between number of CPUs, kernel number and number of threads

Number of CPUs: refers to the physical, as well as hardware on the core number;

The kernel number: logical, simple to understand as the logical simulation of the core number;

Number of threads: the number of programs that the device can execute in parallel at the same time, number of threads =CPU * Kernel number

two number of CPU threads and Java multithreading

First understand a few concepts:

(1) A single CPU thread can only execute a single Java program at the same time, that is, a thread

(2) A single thread can be executed in a single CPU thread at the same time

(3) The thread is the smallest dispatch unit of the operating system, and the process is the smallest unit allocated by the resource (e.g., memory)

(4) All threads in Java in the JVM process, the CPU is scheduling threads in the process

(5) Java multithreading is not because the number of CPU threads is called multiple threads, when the number of Java threads is greater than the number of CPU threads, the operating system uses the time slice mechanism, using the thread scheduling algorithm, frequent thread switching.

A so Java multiple processes, each process and multiple threads, how the CPU is scheduled.

Personal understanding: The operating system is not just evenly distributed CPU to perform different processes, because the thread is the smallest unit of dispatch, so the number of threads in different processes for time slicing, the uniform execution of each thread, that is, a process has 10 threads, and B process has 2 processes, Then the CPU's execution time for the process should theoretically be 5:1.

b The number of CPU threads is directly related to the number of Java threads.

Personal understanding: There is no direct relationship, as mentioned above, the CPU uses a partitioning mechanism to execute threads, dividing a small amount of time into each thread to perform, but in real projects, threads have to do a lot of work, read and write disks, data logic processing, the necessary hibernation for business needs, and so on.

c How to determine the number of program threads.

Personal understanding: Generally, the number of program threads is equal to two to three times times the number of CPU threads to make good use of the CPU, excessive number of program threads will not improve performance, but also because of the frequent switch between threads are affected, the specific needs of the business based on threading the test, and constantly adjust the number of threads, Determines the optimal number of threads for the current system.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.