counter.java
来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 34 行
JAVA
34 行
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 + =
减小字号Ctrl + -
显示快捷键?