Code example for BlockingQueue

Methods: sizedrainTo

0
 
    public synchronized Collection<Message> listenForMessages() {
 
        Collection<Message> msg = new ArrayList<Message>();
 
        if (messages.size() > 0) {
            messages.drainTo(msg);
        } else { 
            try { 
                Message message = messages.take();
                msg.add(message);
 
            } catch (InterruptedException e) {
                e.printStackTrace();
            } 
        } 
 
        return msg;
    } 
} 
Connect your IDE to all the code out there  Get Codota for Java