⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reader.java

📁 21天学通java的示例程序源代码
💻 JAVA
字号:
//Reader.javapackage com.wrox.syncserver;import java.util.Vector;public class Reader extends Thread {  // The queue is the communication channel between  // this reader and the writer.  private Vector queue;  // A name so we can tell the readers apart.  private String name;  /**   * Create a reader to read objects from a queue.   * @param queue Contains the flow of objects from the writer.   * @param name A name so we can distinguish readers.   */  public Reader(Vector queue, String name) {    this.queue = queue;    this.name = name;  }  public void run() {    for (; ; ) {      synchronized (queue) {   // acquire the monitor        while (queue.isEmpty()) {          try {            queue.wait();      // releases the monitor          } catch (InterruptedException ex) {            // Nothing to do here. If the queue is empty,            // might as well go back to waiting.          }         }         // At this point the monitor has been re-acquired        Object o = queue.remove(0);        System.out.println(name + " got job number: " + o);      }                        // release the monitor at the end of the synchronized block     }   } }

⌨️ 快捷键说明

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