たとえば、 r.wait() が機能することを知りたいですか? このコードで:
public class Buffer1<T> {
private T content;
private boolean empty;
private Object r = new Object();
private Object w = new Object();
public Buffer1() {
empty = true; }
public Buffer1(T content) {
this.content = content;
empty = false; }
public T take() throws InterruptedException {
synchronized (r) {
while (empty) {
r.wait();
}
synchronized (w) {
empty = true;
w.notify();
return content;
}
}
}
public void put(T o) throws InterruptedException {
synchronized(w) {
while (!empty) {
w.wait();
}
synchronized (r) {
empty = false;
r.notify();
content = o;
}
r.wait()、w.wait()、r.notify()、w.notify() はどのように機能しますか? また、これらは Synchronized(r) / Synchronized(w) とどのように連携するのでしょうか?