Learning Essentials
Relationship of processes and threads
Multithreaded program run mode
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