假设我们有两个Runnables:

class R1 implements Runnable {
    public void run() { … }
    …
}

class R2 implements Runnable {
    public void run() { … }
    …
}

那么这两者的区别是什么呢:

public static void main() {
    R1 r1 = new R1();
    R2 r2 = new R2();

    r1.run();
    r2.run();
}

这:

public static void main() {
    R1 r1 = new R1();
    R2 r2 = new R2();
    Thread t1 = new Thread(r1);
    Thread t2 = new Thread(r2);

    t1.start();
    t2.start();
}

当前回答

Thread.start()代码向调度器注册线程,调度器调用run()方法。同样,Thread是类,而Runnable是接口。

其他回答

成员们提出的观点都是对的所以我想补充一点。问题是JAVA不支持多继承。但是如果你想从另一个类a中派生一个类B,但你只能从一个类中派生。现在的问题是如何从这两个类中“派生”:A和Thread。因此,您可以使用可运行接口。

public class ThreadTest{
   public void method(){
      Thread myThread = new Thread(new B());
      myThread.start;
   }
}

public class B extends A implements Runnable{...

Start()方法调用Thread扩展类和Runnable实现接口的运行重写方法。

但是通过调用run()它会搜索run方法,但如果类实现了Runnable接口,那么它会调用run()重写Runnable方法。

例:

`

public class Main1
{
A a=new A();
B b=new B();
a.run();//This call run() of Thread because run() of Thread only call when class 
        //implements with Runnable not when class extends Thread.
b.run();//This not run anything because no run method found in class B but it 
        //didn't show any error.

a.start();//this call run() of Thread
b.start();//this call run() of Thread
}

class A implements Runnable{
@Override
    public void run() {
            System.out.println("A ");
    }
}

class B extends Thread {

    @Override
    public void run() {
            System.out.println("B ");
    }
}

`

在第一种情况下,您只是调用r1和r2对象的run()方法。

在第二种情况下,您实际上创建了2个新线程!

Start()会在某个时刻调用run() !

如果你在main方法中执行run(), main方法的线程将调用run方法,而不是你需要运行的线程。

start()方法创建了新的线程,run()方法必须为此执行

Thread.start()代码向调度器注册线程,调度器调用run()方法。同样,Thread是类,而Runnable是接口。