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