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

📄 counter.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 JAVA
字号:
class Counter extends Thread {

  Counter (Museum m, int q) {
    museum = m;
    queue = q;
  }

  public void run () {

    // Decide how many Walkmen are needed for a
    // group of visitors and attempt to hire them
    // (waiting until successful). The visitors are
    // sent off on their own to walk around (by
    // starting a new Visitors thread which runs
    // independently.)
    while (true) {
      int w = a(7);
      museum.hire(queue, w);
      new Visitors (museum, w).start();

      // Wait a bit before the next people arrive
      try {sleep(a(100));}  catch(InterruptedException e) {}
    }
  }

  Museum museum;
  int queue;

  static int a (int x) {
    return (int) (Math.random() * x) +1;
  }

}

⌨️ 快捷键说明

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