📄 counter.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 + -