继承Thread类实现多线程
运行代码
public class MyThread extends Thread{ public static void main(String[] args) { for (int i =0 ;i < 10 ;i ++){ new RunThread().start(); } } } class RunThread extends Thread{ @Override public void run() { System.out.println(Thread.currentThread().getName() ); } }
运行结果
Thread-0 Thread-1 Thread-2 Thread-3 Thread-4 Thread-5 Thread-6 Thread-7 Thread-8 Thread-9