35-Wire Cheng

Source: Internet
Author: User

Learning Essentials

    1. Relationship of processes and threads

    2. Multithreaded program run mode

    3. Methods for defining threads


Multi-Threading vs. Multi-process

Multi-process: Multiple programs can run concurrently in the operating system

Multithreading: There are multiple sequential streams in a program that execute simultaneously

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/50/wKioL1R-5STShpb-AAEFsyIzg5s975.jpg "title=" 1.jpg " alt= "Wkiol1r-5stshpb-aaefsyizg5s975.jpg"/>

Methods for creating threads

Method 1: Define a thread class that inherits the class thread and overrides the method run (), which is called the thread body

Because Java only supports single inheritance, classes with this method can no longer inherit from other classes

Class Firstthread extends thread{//firstthread inherit threadpublic void Run () {//Replication Run method for (int i = 0; i<100; i++) {Syste M.out.println ("Firstthread--->" + i);}}}
Interface test{public static void Main (String args[]) {//Generate thread class object Firstthread ft = new Firstthread ();//Start thread ft.start ();// The thread state for (int i = 0; i<100; i++) {System.out.println ("Main--->" + i);}}}


35-Wire Cheng

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.