class MyThread extends Thread {
private int a;
public MyThread(int a) {
this.a = a;
}
public void run() {
for (int i = 1; i <= a; ++i) {
System.out.println(getName() + " is " + i);
try {
sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
public class MainMyThread {
public static void main(String args[]) {
MyThread thr1, thr2;
thr1 = new MyThread(5);
thr2 = new MyThread(10);
thr1.start();
thr2.start();
}
}
多线程基础
最新推荐文章于 2023-05-17 10:58:57 发布