Java Multithreading Example Explained

Source: Internet
Author: User

A: Knowledge Point statement:

1. Differentiate processes and threads: a process is a static concept, and its execution depends on the thread.

2. Status of the process: Ready (Waiting for CPU execution), run, Abort, block (wait for required resources, enter blocking state)

The main function of the 3.Java program is a thread, which is called the main path. If you create a new thread at this point, it runs in parallel with the main threads.

The constructor method in 4.Java, the main function who executes first?

The main function executes first because main is a static method, and the program executes at the beginning, and the constructor is called only when the class is instantiated.


Two: Instance program

public class GetCurrentThread implements Runnable {Thread th;public getcurrentthread (String threadname) {th = new Thread (t His,threadname); <----DOUBTSystem.out.println ("Get ThreadName" +th.getname ()); Th.start ();} public void Run () {System.out.println (Th.getname () + "is starting ..."); System.out.println ("Current thread Name:" + Thread.CurrentThread (). GetName ());} public static void Main (String args[]) {System.out.println ("Current thread Name:" + Thread.CurrentThread (). GetName ()); n EW getcurrentthread ("1st thread");//new getcurrentthread ("2nd thread");}}


III: Implementation Results



Four: Procedure analysis process (directly with notes)



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.