首页 > 其他 > 详细

A1B2B3 - LockSupport

时间:2020-05-31 17:44:26      阅读:31      评论:0      收藏:0      [点我收藏+]
 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 }

 

A1B2B3 - LockSupport

原文:https://www.cnblogs.com/renguanyu/p/13019854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!