- 327 名前:デフォルトの名無しさん [2007/03/27(火) 22:33:12 ]
- Javaのsynchronizedとwaitとnotifyに関する質問なんだが
www.javaworld.jp/technology_and_programming/-/10941-5.html ここの class Buffer { private int value; private boolean isEmpty = true; public synchronized void putValue(int v) { while (!isEmpty) { try { wait(); } catch (InterruptedException e) { } } notifyAll(); isEmpty = false; value = v; } public synchronized int getValue() { while (isEmpty) { try { wait(); } catch (InterruptedException e) { } } notifyAll(); isEmpty = true; return value; } } これがどうして動くのか分からん。 あるスレッドがgetValueに入ってる間は、ほかのスレッドは getValueにもputValueにも入れないんじゃないのか
|

|