Java通过继承Thread类实现多线程

来源:互联网 发布:js string转jsonarray 编辑:程序博客网 时间:2024/05/16 06:34
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();


}
}
原创粉丝点击