【 以下文字转载自 Programming 讨论区 】
发信人: joking (看一看), 信区: Programming
标 题: java synchronized 问题
发信站: BBS 未名空间站 (Tue Dec 11 16:18:47 2007)
今天看programer_interview看到一个producer-customer并行的问题,用java写的(第7
章section 7.12). Program is written as:
class producer extends Thread {
......
void run() {
while (true) {
try {
putInt();
}
catch (...){};
}
}
private synchronized void putInt() throws ... {
while (index == MAX_CAPACITY) {
wait()
}
buffer[ind
m******t 发帖数: 2416
2
Whatever thread(s) stuck in putInt won't be able to proceed right away. They
would have to wait until the notifier thread exits getInt and releases the
lock.