title: BlockingQueue: put() and isEmpty() do not work together?
body: <p>I would like to have a <code>SynchronousQueue</code> where I insert elements from one thread with <code>put()</code>, so the input is blocked until the element is taken in another thread.</p>
  
  <p>In the other thread I perform lots of calculations and from time to time want to check if an element is already available, and consume it. But it seems that <code>isEmpty()</code> always returns true, even if another thread is waiting at the <code>put()</code> call.</p>
  
  <p>How on earth is this possible? Here is the sample code:</p>
  
  <pre><code>@Test
  public void testQueue() throws InterruptedException {
      final BlockingQueue&lt;Integer&gt; queue = new SynchronousQueue&lt;Integer&gt;();
  
      Thread t = new Thread(new Runnable() {
          @Override
          public void run() {
              while (true) {
                  if (!queue.isEmpty()) {
                      try {
                          queue.take();
                          System.out.println("taken!");
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
                  // do useful computations here (busy wait)
              }
          }
      });
      t.start();
  
      queue.put(1234);
      // this point is never reached!
      System.out.println("hello");
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> Neither isEmpty() nor peek() work, one has to use poll(). Thanks!</p>