Skip to content

Commit 71d131f

Browse files
committed
feat: add test code
1 parent 27ee452 commit 71d131f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

00-code(源代码)/src/com/hi/dhl/algorithms/other/concurrency/_1188/BoundedBlockingQueueLock.java

+23
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,27 @@ public int dequeue() throws InterruptedException {
5656
public int size() {
5757
return queue.size();
5858
}
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+
}
5982
}

00-code(源代码)/src/com/hi/dhl/algorithms/other/concurrency/_1188/BoundedBlockingQueueSync.java

+26
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,30 @@ public int dequeue() throws InterruptedException {
4545
public int size() {
4646
return queue.size();
4747
}
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+
}
4874
}

0 commit comments

Comments
 (0)