title: What's the issue with "Long monitor contention event"
body: <p>I have the following service code where I launch a thread responsible for dispatching messages are they come in.  </p>
  
  <pre><code>       public void run() {
            while (! Thread.interrupted()) {
              try {
                Message msg = null;
                synchronized (_queue) {
                  if (_queue.size() == 0) {
                    _queue.wait(10000);
                  }
  
                  if (_queue.size() != 0) {
                    msg = _queue.poll();
                  }
  
                  if (msg != null) {
                    _dispatcher.dispatch(msg);
                  }
                }
              }
              catch (InterruptedException i) {                }
              catch (Exception e) {                }
            }
        }
    public void add (final Message m){
      if (m == null)
        return;
      synchronized (_queue){
        _queue.add(m);
        _queue.notify();
      }
    }
  </code></pre>
  
  <p>But when this code runs on my android simulator, I get a lot of warnings like the following:</p>
  
  <pre><code>Long monitor contention event with owner method=void com.foo.PrioritizedMessageQueue.run() from PrioritizedMessageQueue.java:58 waiters=0 for 585ms
  </code></pre>
  
  <p>To me, this seems like the most efficient way of writing a queue processor.  When there are not message to process, the processing thread will wait until one is added, and the "add" will notify any waiting thread why a new message is added to the queue.  My thought is the dispatching thread won't use minimal resources when no message exists (as it is blocked).  </p>
  
  <p>However, there is a reason why android is issuing this warning but I wonder why. It is clearly not happy with my thread being blocked this long but why is that an issue?  Isn't this more efficient in that it won't use any CPU cycles while it's waiting?  </p>
  
  <p>Also, should I be worried that android may kill my thread because it's been blocked too long?  I would hate for my thread to be killed but not the service.  If my service is killed, I can handle that, but I can't handle just that one thread being killed.  </p>