title: BlockingQueue Implemetation using ReentrantLock
body: <p>I was writing my own implementation of BlockingQueue for practice. I am trying to avoid using the synchronized keyword for the methods. I would instead like to use ReentrantLock.</p>
  
  <p>What is the best way to write this implementation?  I am not a Java ninja and would greatly appreciate if someone could pinpoint the errors in my code here and suggest better ways of implementing it.</p>
  
  <pre><code>public class MyBlockingQueue&lt;T&gt; {
  
  private Queue&lt;T&gt; queue;
  private AtomicInteger limit = new AtomicInteger(10);
  private Lock put_lock = new ReentrantLock();
  private Lock take_lock = new ReentrantLock();
  private Condition put_condition = put_lock.newCondition();
  private Condition take_condition = take_lock.newCondition();
  
  public MyBlockingQueue(AtomicInteger limit){
      queue = new LinkedList&lt;T&gt;();
      this.limit = limit;
  }
  
  public boolean put(T item) throws InterruptedException{
      put_lock.lockInterruptibly();
      try {
          while(queue.size() == limit.get()) {
              put_condition.await();
          }
          put_condition.signal();
          queue.add(item);
      } finally{
          put_lock.unlock();
      }
  
      return true;
  }
  
  public T take() throws InterruptedException{
      take_lock.lockInterruptibly();
      try {
          while (queue.size() == 0) {
              take_condition.await();
          }
          take_condition.signal();
          return queue.poll();
      } finally {
          take_lock.unlock();
      }
  }
  </code></pre>
  
  <p>Thanks for your time!</p>