码迷,mamicode.com
首页 > 其他好文 > 详细

A1B2B3 - LockSupport

时间:2020-05-31 18:23:14      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:art   start   port   bsp   stat   unpark   ack   thread   rar   

 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

标签:art   start   port   bsp   stat   unpark   ack   thread   rar   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!