📄 consumer.java
字号:
package com.oreilly.tiger.ch10;
import java.io.PrintStream;
import java.util.concurrent.BlockingQueue;
public class Consumer extends Thread {
private BlockingQueue q;
private PrintStream out;
public Consumer(String name, BlockingQueue q,
PrintStream out) {
setName(name);
this.q = q;
this.out = out;
}
public void run() {
try {
while (true) {
process(q.take());
}
} catch (InterruptedException e) {
out.printf("%s interrupted: %s", getName(), e.getMessage());
}
}
private void process(Object obj) {
out.printf("%s processing object:%n '%s'%n",
getName(), obj.toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -