title: Convert wait & notifyAll code to use Java 1.5 Lock object
body: <p>We use code that uses syncronized blocks around segments of code with a lot of wait and notifyAll() calls. We are trying to convert these to use Java 5 Lock.lock() and Lock.unlock() methods. How do I migrate this code to remove all the wait and notifyAll calls. I do not know the equivalent to these using the new Locking features.</p>
  
  <p>Any links with examples would be appreciated.</p>
  
  <p>Thanks in Advance</p>
  
  <p>Eq., the following code needs to be converted to use Lock.lock() and lock.unlock The first part to remove the synchronized block is simple as I just need to call lock() method. The question is what can be done for the notifyAll() and wait methods.</p>
  
  <pre>
       synchronized( LOCK )
              {
                  while( !Thread.interrupted() )
                  {
                   try
                      {
  
                          working = runRules();
  
                          if( !working )
                              LOCK.notifyAll();
  
                          LOCK.wait( working ? shortTimeout : longTimeout );
                      }
                      catch( final InterruptedException e )
                      {
                          Package.log.info( "Thread was interrupted.  Exiting.", e );
                          return;
                      }
                  }
              }
  </pre>