1 Public classmainthread{2 Public Static voidMain (String args[]) {3 //The first way to start a thread4Otherthread ot=NewOtherthread ();5Thread t=NewThread (OT);6 T.start ();7 8 //The second way to start a thread9Itemthread it=NewItemthread ();Ten It.start (); One A for(inti=0;i<100;i++){ -System.out.println ("Main Thread:------" +i); - } the } - } - - classOtherthreadImplementsrunnable{//implements the Runnable interface, the JDK knows you are a threading class + Public voidrun () { - for(inti=0;i<100;i++){ +System.out.println ("Other Thread:" +i); A } at } - } - - classItemthreadextendsthread{ - Public voidrun () { - for(inti=0;i<100;i++){ inSystem.out.println ("Item Thread"); - } to } +}
Horse Soldier: A thread is a different execution path within a program. It's enough to understand the concept.
Process: Just a static concept, a class file on the machine, an EXE file called a process
In fact, the thread is running, the process is a static concept, the process is not running, and the process is running the main process.
DOS is only supported for single-process, at the same point in time only one process in the execution
Use interface is flexible, can use interface when try not to inherit from thread class
The Run () method ends and the thread ends
Java.lang.Thread Use and summary