同期ブロック内に待機を書きましたが。私は得てIllegalMonitorStateException
います。では、その理由は何ですか?
package trials;
public class WaitNotifyTrial {
public static void main(String[] args){
Generator g=new Generator();
g.start();
System.out.println("Start");
synchronized (g) {
try {
g.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("Printing exception");
e.printStackTrace();
}
System.out.println(g.value);
}
}
}
class Generator extends Thread{
int value;
public void run(){
synchronized (this) {
value=10;
}
notify();
}
}
}