public static void wait(Object lock,long timeout){
  try {
synchronized (lock) {
      lock.wait(timeout);
    }
  }
 catch (  InterruptedException e) {
  }
}

public static void wait ( Object lock , long timeout ) { try { synchronized ( lock ) { lock . wait ( timeout ) ; } } catch ( InterruptedException e ) { } }
locks the object ( synchronized ) before calling wait
