Thread类与Runnable接口区别:
1.继承Thread是单继承,无法实现多继承和资源共享
2.实现Runnable的类,可以实现资源的共享
package cn.zxx.base;
/**
*
* 实现extends Thread 的线程
*
*/
public class ThreadTest extends Thread{
private String name;
public ThreadTest(String name) {
super();
this.name = name;
}
@Override
public void run() {
for(int i=0;i<11;i++){
System.out.println("抢票:"+name+"\t次数:"+i);
}
}
}
package cn.zxx.base;
/**
*
* 实现implements Runnable 的线程
*
*/
public class ThreadTest2 implements Runnable {
private String name;
public ThreadTest2(String name) {
super();
this.name = name;
}
@Override
public void run() {
for(int i = 0;i<11;i++){
System.out.println("线程:"+name+"\t次数:"+i);
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/17b352d93decb89cb48f5c08d88cfed1.png)