编写一个程序,开启 3 个线程,这三个线程的 ID 分别为A、 B、 C,每个线程将自己的 ID 在屏幕上打印 10 遍,要求输出的结果必须按顺序显示。
如: ABCABCABC…… 依次递归
代码实现:通过主函数唤醒线程实现
package thread;
class outPrint implements Runnable{
private String name;
outPrint(String name){
this.name=name;
}
@Override
public void run() {
System.out.println(name);
}
}
public class Demo2 {
public static void main(String[] args) throws InterruptedException {
outPrint opa=new outPrint("A");
outPrint opb=new outPrint("B");
outPrint opc=new outPrint("C");
for (int i = 0; i < 10; i++) {
Thread ta=new Thr