Java Multithreading Overview

Source: Internet
Author: User
Tags thread class

Thread? Process? What is a thread? What is the process? These questions will probably have been heard ~

Process is composed of multiple threads, the program once run, there will be processes exist, the general program will have one or more processes exist, a process may exist one over multiple threads, the different threads will not interfere;

Java implementation of multi-threaded a total of two methods, the first is to inherit the thread class, the second is to implement the Runnable interface, and then are the replication run method, in the Run method to implement their own code to implement, and then start the thread by starting method, The Run method is then automatically called:

Specific multi-threaded see the following demo:

 PackageCom.seven.thread; Public classMyfirstthread { Public Static voidMain (string[] args) {//Open Thread        NewThread (NewMyThread ()). Start ();  for(intI= 0;i<100;i++) {System.out.println ("Main" +i); }            }}classMyThreadextendsthread{ Public voidrun () { for(inti=0;i<100;i++) {System.out.println ("Mythread" +i); }    }    }

From this example, we can see the main characteristics of our thread, the custom thread and the main function think of the thread is at the same time, each run structure will be inconsistent!

Java Multithreading Overview

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.