这是一道面试题,创建多线程时,使用继承Thread类和实现Runnable接口有哪些区别呢?
一、Thread
先来看看Thread类和其中的start()方法
class Thread implements Runnable{
.....}
// 可见,Thread类实现了Runnable接口
public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0)
throw new IllegalThreadStateException();
/* Notify the group that this thread is about to be started
* so that it can be added to the group's list of threads
* and the group's unstarted count can be decremented. */
group.add(this);
boolean started = false;