logger.java

来自「一步 教你学会java 完成一个完整的SWT系统 是本人学习java」· Java 代码 · 共 44 行

JAVA
44
字号
/** *  Example code for JavaOne hands-on J2SE lab * *  Concurrency utilities (JSR-166) example **/package queue;import java.net.*;import java.io.*;import java.util.concurrent.*;/** *  Runnable that consumes information placed in a blocking queue.  This *  demonstrates the simple synchonisation that can be achieved with the *  new BlockingQueue class. **/public class Logger implements Runnable {  private BlockingQueue<String> messageQueue;  /**   *  Constructor   *   * @param messageQueue The queue that will be used to pass messages   * between the two threads   **/  public Logger(BlockingQueue<String> messageQueue) {    this.messageQueue = messageQueue;  }     /**   *  Run method simply takes messages from the queue when they're there   *  and pushes them to the stdout   **/  public void run() {    try {      while (true) {        System.out.println("LOG MSG: " + messageQueue.take());      }    } catch (InterruptedException ie) {      // Ignore    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?