public class Example2_4 extends Thread{
public static void main(String[] args) {
//初始化线程
Example2_4 e = new Example2_4();
//启动线程
e.start();
System.out.println("----");
try {
for (int i = 0; i < 10; i++) {
//延时1s
Thread.sleep(1000);
System.out.println("main:"+i);
}
} catch (Exception e2) {
// TODO: handle exception
}
}
public void run(){
try {
for (int i = 0; i < 10; i++) {
//延时2s
Thread.sleep(2000);
System.out.println("run:"+i);
}
} catch (Exception e2) {
// TODO: handle exception
}
}
}
继承Thread类
最新推荐文章于 2022-08-01 17:14:29 发布