Java multi-thread learning notes

Source: Internet
Author: User

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.

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.