Thread类创建线程
通过代码来理解:
?
public class ThreadDemo {public static void main(String[] args) {new TestThread().start();while(true){System.out.println("main is running !");}}}class TestThread extends Thread{@Overridepublic void run() {while(true){System.out.println(Thread.currentThread().getName()+" is running!");}}}
?
理解:
(1),要实现多线程,必须编写一个继承Thread的子类,并覆盖父类的run方法。这个run方法就写你想让新线程干的事情!
(2),启动线程是调用Thread子类中的start方法,而不是run!