📄 mod11ans.lst
字号:
listing 1
// Make the TickTock class actually keep time.
class TickTock {
synchronized void tick(boolean running) {
if(!running) { // stop the clock
notify(); // notify any waiting threads
return;
}
System.out.print("Tick ");
// wait 1/2 second
try {
Thread.sleep(500);
} catch(InterruptedException exc) {
System.out.println("Thread interrupted.");
}
notify(); // let tock() run
try {
wait(); // wait for tock() to complete
}
catch(InterruptedException exc) {
System.out.println("Thread interrupted.");
}
}
synchronized void tock(boolean running) {
if(!running) { // stop the clock
notify(); // notify any waiting threads
return;
}
System.out.println("Tock");
// wait 1/2 second
try {
Thread.sleep(500);
} catch(InterruptedException exc) {
System.out.println("Thread interrupted.");
}
notify(); // let tick() run
try {
wait(); // wait for tick to complete
}
catch(InterruptedException exc) {
System.out.println("Thread interrupted.");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -