1 package a1b2c3;
2
3 import java.util.concurrent.locks.LockSupport;
4
5 /**
6 * A1B2C3问题 - LockSupport实现
7 * @author renguanyu
8 *
9 */
10 public class A1B2C3_LockSupport_Demo {
11
12 static Thread t1 = null;
13 static Thread t2 = null;
14
15 public static void main(String[] args) throws InterruptedException {
16
17 char[] ch1 = "ABCDEF".toCharArray();
18 char[] ch2 = "123456".toCharArray();
19
20 t1 = new Thread(() -> {
21
22 for (char c : ch1) {
23
24 System.out.print(c);
25
26 LockSupport.unpark(t2);
27
28 LockSupport.park(t1);
29
30 }
31 });
32 t2 = new Thread(() -> {
33
34 for (char c : ch2) {
35
36 LockSupport.park(t2);
37
38 System.out.print(c);
39
40 LockSupport.unpark(t1);
41
42 }
43 });
44
45 t1.start();
46 t2.start();
47
48 }
49
50 }