What is the difference between java start () and run ()
This article introduces the relevant knowledge of "what is the difference between java start () and run ()". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Conceptual differences
Start (): after generating the thread object, call the start () method to start the thread, and the thread is in the Ready ready state in the running state RUNNABLE. At this time, the thread waits to be scheduled by CPU, and then executes the run () method, and uses the start () method to start the thread, which really realizes multithreading.
The run (): run () method is a common method in Thread, which calls the run () method directly with the thread object and runs in the main thread. Because there is only one main thread in the program, when there are two threads in the program, the run () method is called directly. The program executes sequentially and does not implement multithreading.
2. Examples
Public static void main (String [] args) {Thread T1 = new Thread (new Runnable () {@ Override public void run () {System.out.println (Thread.currentThread (). GetName ());}, "unstoppbale_t"); t1.start ();} "what's the difference between java start () and run ()". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!