Multi-threaded on the CPU how distribution

Questions about Java multi-threaded on the CPU distribution, we must first understand that it is a multi-core or dual-core CPU and are not necessarily linked. Sometimes CPU can only perform one thread, since when the multi-threaded parallel execution, CPU and thread switching may be scheduled according to certain algorithms. For general multithreaded CPU may be appreciated that according to certain thread switching thread scheduling algorithm, so the corresponding time slots, can be seen as a plurality of threads concurrently executed. But at a certain point in time only one thread is actually running.

 

There concurrent programming and CPU clock concussion two key issues in the Java multithreading. We all know that a long time ago the DOS system, can only perform a single task. And we can now use the Windows multi-task operation, while chatting on the Internet, listen to songs while to download movies and so on. So, what operating system supports multitasking? Each open a program, it means starting a process and its corresponding memory space allocation, which would allow the program to run concurrently. The clock frequency of the CPU, the number of CPU-executable instructions per second i.e., in a single clock cycle, actually only execute a CPU (or a plurality of instructions).

Operating system to manage the process thread, the time allocated for each process, and then within each process, the program code deal with their own internal allocation of time in the process thread, to be carried out within a very short time between multiple threads to each other switch. Therefore, it gives the impression that multiple tasks, multiple threads are running concurrently, but in fact, running or asynchronous program.

 

Since it is run asynchronously, so it can be understood as the CPU operating mode it is serial, rather than parallel, so we call multi-threading What is the significance? Shangxue Tang battle programmer Chen pointed out that the reason is the CPU running too fast, but we read speed I / O, the transmission network, database connections, and so the CPU speed than it is very slow of. In order to make full use of CPU, it can reduce the idle time of the CPU.

Multithreaded object is to maximize the use of CPU resources, the CPU, the higher the frequency = FSB × multiplier, frequency, number of instructions in a clock cycle which is the more complete, of course, the faster cpu the previous increase CPU speed way is to increase the CPU clock speed, but over time, CPU clock speed has reached the physical limits, difficult to improve. So in order to solve this problem, the multi-core CPU began to gradually favored by the people.

 

About Java multi-threaded There are two important questions:

First briefly talk about the issue of terms of memory, in Java, all variables are stored in main memory, each thread has its own working memory (Working Memory), the contents of working memory is usually stored copy of main memory variables . Threaded operation for all variables were carried out in the working memory, can not directly access each other between threads, pass variables also need to be completed in main memory. Simple communication between threads and quick, between processes are independent of each other, can not communicate between network if you do not rely on the process.

Followed by the issue of thread scheduling, thread for each CPU scheduling is random (time-sharing scheduling), whereas in Java, JVM thread is responsible for scheduling, can better allocate the right to use the CPU. For scheduled thread generally it has two modes, time-sharing scheduling and preemptive scheduling. Sharing equally distributed scheduling order; preemptive scheduling is allocated according to priority.

 

These are the questions about the distribution of multi-threaded on the CPU simple discussion to help people deepen their understanding of multi-threaded.

 

Reprinted    https://blog.csdn.net/qq_29824717/article/details/82561301

Guess you like

Origin blog.csdn.net/yucaixiang/article/details/95207019