title: IllegalMonitorStateException inside synchronized block
body: <p>Though I have written wait inside synchronized block. I am getting <code>IllegalMonitorStateException</code>. What's the reason then?</p>
  
  <pre class="lang-java prettyprint-override"><code>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();
          }
      }
  }
  </code></pre>