Java multi-thread learning notes
-- @ Liang WP
(1) When running an application, a process is started. Some programs start multiple processes.
(2) In the process, some program blocks can be executed in disorder and the code block can be executed multiple times at the same time. Such a code block is the thread body, A thread is a code flow executed in disorder.
(3) The multi-process of the operating system achieves multi-task concurrent execution, the multi-thread of the program achieves concurrent execution of the process, and the multi-thread aims to maximize the use of CPU resources.
(4) Each Thread has a priority. The execution of a high-priority Thread takes precedence over a low-priority Thread. When the code running in a Thread creates a new Thread object, the initial priority of the new thread is set to the priority of the created thread.
(5) When the program starts and runs main, the Java Virtual Machine starts a process and the main thread is created when main () is called.
(6) construct an object through the Thread class constructor Thread (Runnable target), and then call the start () method of the Thread object to start the Thread.
(7) after the start () method is called, it does not execute multi-threaded code immediately, but changes the thread to an executable Runnable state. The operating system determines when the thread runs.
(8) The results of running the program show that multi-threaded programs are executed in disorder. Therefore, it is necessary to design the code in disorder into multiple threads.
(9) Call the Thread. CurrentThread (). getName () method in a method to obtain the name of the current Thread. For example, you can call this method in main () to obtain the name of the main thread.