创建线程的方法
1.继承Thread类来创建线程,这个方法的好处是this代表的就是当前线程,不需要通过Thread.currentThread()来获取当前线程的引用。
public class main {
public static class myThread extends Thread{
@Override
public void run() {
System.out.println("创建出来的线程");
}
}
public static void main(String[] args) {
myThread t1=new myThread();
t1.start();
}
}
2.实现Runnable接口,并且调用Thread的构造方法时将Runnable对象作为target参数传入来创建线程对象,好处是可以规避类的单继承限制,但需要通过Thread.currentThread()来获取当前线程的引用。
public class main {
public static class MyRunnbale <