title: what does notify and wait mean in java?
body: <p>I have code that I am learning about <code>Thread</code>. I don't understand how it works in my code below. My code is working on traffic light processing. Can you explain in code below?</p>
  
  <pre><code>public void run(){
      while(!stop){
          try{
              switch(lc){
                  case GREEN:
                      Thread.sleep(1000);break;//pause for ten second;
                  case RED: 
                      Thread.sleep(2000);break;
                  case YELLOW:
                      Thread.sleep(1000);break;
              }
          }
          catch(Exception exc){}
           colorChange(); 
      }
  
  }
  synchronized void colorChange(){
      switch(lc){
          case GREEN:
              lc=LightColor.YELLOW;break;
          case YELLOW:
              lc=LightColor.RED;break;
          case RED:
              lc=LightColor.GREEN;break;
      }
      changed=true;
      notify();
  }
  synchronized void waitChange(){
      while(!changed)
           try {
               wait();
               changed=false;
          } catch (InterruptedException ex) {
              Logger.getLogger(ControlLight.class.getName()).log(Level.SEVERE,null, ex);
          }
  
  }
  </code></pre>