Start right basics of eight core 2. Thread the threads and the wrong way

I. Overview

 

 

 Two .start () and run () comparison

1. Code demo

analysis:

  • Calls the run method is executed by the main thread

  • Call start method is performed by a newly created thread of

/ ** 
 * Comparative start and run two start threads way 
 * / 
public  class StartAndRunMethod { 

    public  static  void main (String [] args) {
         // 1. direct calling run 
        the Runnable Runnable = () -> { 
            the System.out .println (Thread.currentThread () getName ().); 
        }; 

        Runnable.run (); // main 

        // 2. start method using the 
        new new the Thread (Runnable) .start ();    // the Thread-0 
    } 
}

2.start principle of the method Interpretation

(1) start Method Meaning

  • Start a new thread

  • Ready to work

  • Can not be repeated start ()

(2) start source code analysis

 

Guess you like

Origin www.cnblogs.com/zhihaospace/p/12466818.html