class Thread01 extends Thread {
int a = 0;
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
while (a <= 2) {
System.out.println(a++ + " ");
try {
sleep(500);
this.sleep(500);
Thread.sleep(500);
Thread01.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
class Thread02 extends Thread {
int a = 0;
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
while (a <= 2) {
System.out.println(a++ + " ");
try {
this.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public class test0 {
public static void main(String[] args) {
Thread01 a1 = new Thread01();
Thread02 a2 = new Thread02();
a1.start();
a2.start();
}
}
Java通过继承Thread类实现多线程
最新推荐文章于 2021-03-08 07:11:01 发布