go: Basic Learning Summary----thread (i) Http://www.cnblogs.com/xdp-gacl/p/3633936.htmljava
First, the concept of threading
thread : A thread is a different execution path within a program
process : A static concept, A. class file on a machine, an. exe file on the machine, which is called a process.
program execution Process :
1. First put the code of the program into the code area of the memory, the code is placed in the code area and did not immediately start execution, but this time shows that a process is ready to start, the process has been generated, but has not started to execute, this is the process. It's actually 2. The execution of a process refers to the process in which the main thread (that is, the main () method) begins to execute.
3. A process is a static concept in which the threads are actually running in our machine.
4. In fact, at a point in time, the CPU has only one thread running, because the CPU is running fast, so we look like a multi-threaded.
Second, thread creation and start-up
1. In Java, Java threads are implemented by the Java.lang.Thread class, and each thread object represents a new thread.
2. You just have to new a thread object, and a fresh one will appear.
3. each thread completes its operation by means of the method run ( ) that corresponds to a particular thread object, and the method run () is called the thread body.
Public classTestThread1 { Public Static voidMain (String args[]) {//new A thread class object R1,r1 to invoke the run () method to startRunner1 R1 =NewRunner1 (); //to start a new thread, T has to new a thread object.//This is the thread (Runnable target) construction method used here.Thread T =NewThread (R1); //The start thread t,t thread executes the run () method, which is executed in parallel with the main thread R1T.start (); for(inti = 0; I < 10; i++) {System.out.println ("Maintheod:" +i); } }}//defining a class to implement the Runnable interface, implementing the Runnable interface means that the class is a thread classclassRunner1Implementsrunnable{ Public voidrun () { for(inti = 0; I <10; i++) {System.out.println ("Runner1:" +i); } }}
public class TestThread1 {public static void main (String args[]) {//new A thread class object R1,r1 to invoke the run () method to start Runner1 r1 = new Runner1 ( );//To start a new thread T must be new a thread//is used here is the thread (Runnable target) construction method Thread T = new thread (r1);//start thread t,t thread executes the run () method, It is executed in parallel with the main thread R1 T.start (); for (int i = 0; i <; i++) {System.out.println ("Maintheod:" + i);}}} Defining a class to implement the Runnable interface, implementing the Runnable interface means that the class is a threading class Runner1 implements Runnable{public void Run () {for (int i = 0; i < 10; i++) {System.out.println ("Runner1:" + i);}}}
Java Basic Learning Summary-----Thread (i)