Java thread start of and run of methods

  • 2020-04-01 01:10:22
  • OfStack

1. Start () method To start the thread, the true implementation of multithreading, then without waiting for the run method body code to complete the execution of the following code directly continue to execute:
To start a Thread by calling the start() method of the Thread class,
This thread is now in the ready state,
It's not running.
The Thread class then calls the method run() to complete its operation,
Here the method run() is called the body of the thread,
It contains the contents of the thread to execute,
The Run method runs out,
This thread terminates,
And the CPU runs another thread,

2. Run () method Called as a normal method, the program still has to be executed sequentially, or wait for the body of the run method to complete before continuing to execute the following code:
If you just use the Run method,
This is just calling a method,
There's still only the main thread in the program -- this one thread,
The execution path of the program is still only one,
This does not achieve the purpose of the writer thread.

Related articles: