Example usage for java.util.concurrent ConcurrentLinkedQueue wait

List of usage examples for java.util.concurrent ConcurrentLinkedQueue wait

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentLinkedQueue wait.

Prototype

public final void wait() throws InterruptedException 

Source Link

Document

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Usage

From source file:net.jmhertlein.mcanalytics.plugin.daemon.ClientMonitor.java

private void write(PrintWriter out) {
    ConcurrentLinkedQueue<JSONObject> queue = dispatcher.getWriteQueue();
    while (!shutdown) {
        if (queue.isEmpty()) {
            synchronized (queue) {
                try {
                    queue.wait();
                    System.out.println("CL-WRITE: Got something to write!");
                } catch (InterruptedException ex) {
                }//w ww  .  j a  va2 s .  c  om
            }
        } else {
            String w = queue.remove().toString();
            //System.out.println("CL-WRITE: WRITING THIS:=======================");
            //System.out.println(w);
            //System.out.println("==============================================");
            out.println(w);
            out.flush();
        }
    }

    //System.out.println("CL-WRITE: Exiting, turning off the lights...");
    try {
        close();
    } catch (IOException ex) {
        Logger.getLogger(ClientMonitor.class.getName()).log(Level.SEVERE, null, ex);
    }
}