启动三个线程循环打印ABC10次
public class Test implements Runnable {private static char[] chars = new char[] { 'A', 'B', 'C' };private static Integer index = 0; // 临界资源private int count = 10;public static void main(String[] args) {new Thread(new Test()).start();new Thread(new Test()).start();new Thread(new Test()).start();}public void run() {while (true) {synchronized (index) {if (index == 3*count){return;}System.out.println(chars[index % 3]);index++;}}}}