父类使用了runnable接口,子类继承父类,那么调用子类的start()方法后,会产生几个线程?
//父类
public class father implements Runnable {
public void run() {}
}
//子类
public class son {
public void run() {super.run();}
}
大概的意思就是像代码那样,不知道会创建多少个线程,怎么查看线程数目呢?
你执行一次,就创立一个线程。
Runnable本身不是线程,Thread的才是,new Thread(Runnable)才是创建了一个线程。是Thread类调用了Runnable类的run方法。
你创建线程时根据传入的Runnable参数调用相应的run方法。如果你传递的是子类,就是子类的run.真正线程创建是根据你new了多少个Thread决定的。
建议你去看看线程创建的两种方法。祝好!
看你new 几个对象 ,runnable本省是一个接口,实现后还是要丢进 new Thread()坐位参数,runnable的好处是可以加一些自己的东西(大多数是声明一些异常)