Code example for LinkedBlockingQueue

Methods: add

        this.timeout = timeout;
        this.options = options;
    public synchronized void add(String key) {
        queue.add( key );
    public int getTimeout() { 
        return timeout;
    //this is the blocking code  
    public synchronized String getNextMessage(int timeout) throws InterruptedException {
        return queue.poll( timeout, TimeUnit.SECONDS );
    public synchronized String getNextMessage() {
        return queue.poll();
Stop searching for code, let great code find you!  Add Codota to your java IDE