Multithreading the Thread class inheritance

* One way to create multiple threads: Thread class inheritance 
* java.lang.Thread is multi-threaded class description, to achieve multi-threaded program, a way that inherit the Thread class
* 1. Create a class Mythread allowed extends Thread class
* 2. rewrite the run method of the thread class in the Mythread class, sets the threaded tasks (it doing things)

* 3. Create objects Mythread class 
* 4. Call the start method of the Thread class, open a new thread executes the run method
* void start () Causes this thread to begin execution, java virtual machine calls the run method of this thread
* Then two concurrent threads begin execution; the current thread (main main thread) and another thread (new thread is created, which executes its run method) 
* repeatedly to start a thread is illegal, especially when a thread has completed execution and can not be restarted
* execute java program is part preemptive scheduling (consistent with the mainstream operating system scheduling), who is a high priority of whoever executed, the priority is the same as random selection execution

 Printing concurrent execution result of a program (part results, it can be seen executed concurrently)

 

Guess you like

Origin www.cnblogs.com/cdlyy/p/11563729.html