File tree 2 files changed +49
-0
lines changed
00-code(源代码)/src/com/hi/dhl/algorithms/other/concurrency/_1188
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -56,4 +56,27 @@ public int dequeue() throws InterruptedException {
56
56
public int size () {
57
57
return queue .size ();
58
58
}
59
+
60
+ public static void main (String ... args ){
61
+ BoundedBlockingQueueLock lock = new BoundedBlockingQueueLock (20 );
62
+ for (int i = 1 ;i <30 ;i ++){
63
+ Thread tha = new Thread (()->{
64
+ try {
65
+ lock .enqueue (2 );
66
+ } catch (Exception e ){
67
+
68
+ }
69
+ });
70
+ tha .start ();
71
+
72
+ Thread thb = new Thread (()->{
73
+ try {
74
+ System .out .println (lock .dequeue ());
75
+ } catch (Exception e ){
76
+
77
+ }
78
+ });
79
+ thb .start ();
80
+ }
81
+ }
59
82
}
Original file line number Diff line number Diff line change @@ -45,4 +45,30 @@ public int dequeue() throws InterruptedException {
45
45
public int size () {
46
46
return queue .size ();
47
47
}
48
+
49
+ public static void main (String ... args ){
50
+ BoundedBlockingQueueSync sync = new BoundedBlockingQueueSync (20 );
51
+ for (int i = 0 ;i < 20 ;i ++){
52
+ Thread tha = new Thread (() ->{
53
+ try {
54
+ sync .enqueue (2 );
55
+ }catch (Exception e ){
56
+
57
+ }
58
+ });
59
+ tha .start ();
60
+
61
+
62
+ Thread thb = new Thread (()->{
63
+ try {
64
+ sync .dequeue ();
65
+ } catch (Exception e ){
66
+
67
+ }
68
+ });
69
+ thb .start ();
70
+ }
71
+
72
+
73
+ }
48
74
}
You can’t perform that action at this time.
0 commit comments