package xiancheng;
//以继承方式支持多线程
public class Test2 extends Thread{
//重写fun方法
//fun方法是用来被star()自动调用
@Override
public void run() {
//调用需要并发执行的语句
test();
}
//测试方法
public void test()
{
// 线程测试
for(int i=1; i<=10; i++)
{
System.out.println(Thread.currentThread().getName()+"="+i);
//通过线程类控制线程
try {
Thread.sleep(1000);//主线程休眠1000毫秒
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}
public class Test1 {
public static void main(String[] args) {
//先实例化
Test2 t2 =new Test2();
t2.setName("张店");
t2.start();
Test2 t3 =new Test2();
t3.setName("桓台");
t3.start();
}
}