public void callSeriallyAndWait(Runnable r,int timeout){
  RunnableWrapper c=new RunnableWrapper(r,0);
  callSerially(c);
synchronized (lock) {
    long t=System.currentTimeMillis();
    while (!c.isDone()) {
      try {
        lock.wait(20);
      }
 catch (      InterruptedException err) {
      }
      if (System.currentTimeMillis() - t >= timeout) {
        return;
      }
    }
  }
}

public void callSeriallyAndWait ( Runnable r , int timeout ) { RunnableWrapper c = new RunnableWrapper ( r , 0 ) ; callSerially ( c ) ; synchronized ( lock ) { long t = System . currentTimeMillis ( ) ; while ( ! c . isDone ( ) ) { try { lock . wait ( 20 ) ; } catch ( InterruptedException err ) { } if ( System . currentTimeMillis ( ) - t >= timeout ) { return ; } } } }
identical to callserially with the added benefit of waiting for the runnable method to complete .
