File tree Expand file tree Collapse file tree 2 files changed +2
-6
lines changed
src/com/lld/myblockingqueue Expand file tree Collapse file tree 2 files changed +2
-6
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,8 @@ public MyBlockingQueue(int capacity) {
3030 public void put (E item ) throws InterruptedException {
3131 Objects .requireNonNull (item );
3232
33+ lock .lock ();
3334 try {
34- lock .lock ();
35-
3635 while (size .get () == capacity ) {
3736 canPut .await ();
3837 }
@@ -48,9 +47,8 @@ public void put(E item) throws InterruptedException {
4847 }
4948
5049 public E get () throws InterruptedException {
50+ lock .lock ();
5151 try {
52- lock .lock ();
53-
5452 while (size .get () == 0 ) {
5553 canTake .await ();
5654 }
Original file line number Diff line number Diff line change 11package com .lld .myblockingqueue ;
22
3- import java .util .Random ;
4-
53public class Producer implements Runnable {
64 private MyBlockingQueue <Integer > myBlockingQueue ;
75
You can’t perform that action at this time.
0 commit comments