采用Thread+Semaphore实现,思路很简单 import java.io.IOException; import java.util.concurrent.Semaphore; public class PrintABC { public static int MAX_TIME = 10; public static class PrintThread extends Thread { private String printChar; private Semaphore curSem…
https://blog.csdn.net/weixin_39723337/article/details/80352783 题目:3个线程循环打印ABC,其中A打印3次,B打印2次,C打印1次,循环打印2轮一.Synchronized同步法思路:使用synchronized.wait.notifyAll的方法利用线程标记变量控制三个线程的执行顺序. /** * @author XDarker * 2018-5-17 */public class Main { public static voi…
1. synchronized实现双线程交替打印 class Print implements Runnable{ static int i=0; static final int n=100; @Override public void run() { synchronized (this) { while (i < n) { System.out.println(i++ + Thread.currentThread().getName()); notify(); try { Thread.s…