title: Java wait() does not get waked by notify()
body: <p>Hallo I've been debugging my code for a whole day already, but I just can't see where could be wrong.</p>
  
  <p>I use SerialPortEventListener on a main thread, in a working thread I have a client socket communicating to a server.
  Since after this working thread reach <code>return</code>, I still need some wrap up work done in the main thread, i want to create a "pseudothread" that wait in the main thread until the it is notified from the listener onEvent method.</p>
  
  <p>but this pseudothread seems to be waiting forever.</p>
  
  <p>I checked the locked thread <code>pseudoThread</code>, they should have the same object id in the Runnable and in Listener class. </p>
  
  <p>"PseudoThread waiting" got displayed, but PseudoThread awake is never showed.</p>
  
  <blockquote>
    <p>Console output shows: 
    PseudoThread waiting 
    ..
    ..
    false notified pseudothread.</p>
  </blockquote>
  
  <p><strong>PS if I create a lock in Main class with <code>public final Object lock = new Object();</code> and replace all <code>main.pseudoThread</code> with <code>main.lock</code>, I get java.lang.IllegalMonitorStateException.</strong></p>
  
  <pre><code>private class Pseudo implements Runnable{
      Main main;
      public Pseudo(Main main) {
          this.main = main;
      }
  
      @Override
      public void run() {
          synchronized(main.pseudoThread){
              try {
                  System.out.println("PseudoThread waiting");
                  main.pseudoThread.wait();
                  System.out.println("PseudoThread awake");
              } catch (InterruptedException e) {
                  e.printStackTrace();
                  return;
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p>in main method:</p>
  
  <pre><code>public static void main(String[] args) {
      Main main = new Main();
      main.initArduino();
      //more code. including starting the working thread
      main.pseudoThread = new Thread(main.new Pseudo(main));
          main.pseudoThread.start();
          try {
              main.pseudoThread.join();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
  }
  private void initArduino() {
      arduino = new Arduino(this);
      if(!arduino.initialize())
          System.exit(1);
  }
  </code></pre>
  
  <p>and in the listener class (which also runs in main thread)</p>
  
  <pre><code>//class constructor;
  public Arduino(Main Main){
      this.main = Main;
  }
  //listening method
  public void serialEvent(SerialPortEvent oEvent){
      //some code to interract with working thread.
      record();
  
  }
  private void record(){
          synchronized(main.pseudoThread){
              main.pseudoThread.notify();
              System.out.println("notified pseudothread.");
          }
  }
  </code></pre>