Thread implementation steps:
Define a subclass of Thread, override the run() method, run( ) method represents the task to be completed by the thread, and the run() method is called the thread execution body.
Create an instance of the Thread subclass, and the subclass object is the thread.
Call the start() method of the thread object to start the thread.
<code>public class ThreadDemo extends Thread{<br><br> public void run() {<br> for(int i=0;i<10;i++) {<br> System.out.println(currentThread().getName()+":" + i);<br> }<br> }<br><br> public static void main(String args[]) {<br> new ThreadDemo().start();<br> new ThreadDemo().start();<br> }<br>}</code>
The above is the detailed content of How to create a Java thread class by inheriting the Thread class. For more information, please follow other related articles on the PHP Chinese website!