title: notify() and wait() not working in Java
body: <p>I have 2 threads which I want to synchronize with wait() and notify(). However when I notify the thread which waits never resumes. This are my pieces of code.
  In Lib60870 i start both threads, and thread HandShake is synchronized with SerialReader.</p>
  
  <pre><code>public Lib60870(){ //Here I start threads
      try {
          myConnection=new Connection(LOCALHOST,port);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      mySerialReader.start();
      myHandshake.start();}
  }
  </code></pre>
  
  <p><strong>Class SerialReader</strong></p>
  
  <pre><code>public class SerialReader extends Thread {
  
  private static boolean isPaused=true;
  
  @Override
  public void run() {
      synchronized(this){
          if(Lib60870.myConnection!=null){
              while(true){
                  if(!isPaused){
                      byte inByte=Lib60870.myConnection.getByte();
                      if(inByte==0x68){
                          ...
                          }
                          notify();
                      }
                      else if(inByte==0x10){
                          ...         
                          }
                          notify();
                      }
                  }
              }
          }
      }
  }
  
  public void setPause(boolean pause){
      isPaused=pause;
  }
  </code></pre>
  
  <p><strong>Class Handshake</strong></p>
  
  <pre><code>public class HandShake extends Thread {
  
  
  public void run() {
      synchronized(Lib60870.mySerialReader){
          Lib60870.mySerialReader.setPause(false);
          ...
          try {
              Lib60870.mySerialReader.wait();
          } catch (InterruptedException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
          Lib60870.mySerialReader.setPause(true);
          ...
          Lib60870.mySerialReader.setPause(false);
          try {
              Lib60870.mySerialReader.wait();
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks in advance</p>