try { Thread.currentThread().sleep(1000); } catch (InterruptedException e) {}
try { Thread.sleep(1000); } catch (InterruptedException e) {}
  public static void main(String args[]) {    System.out.println("TestTimedWait");    int     cnt     = 20;    Mailbox mailbox = new Mailbox(cnt);    Flag    flag    = new Flag();    Task    tasks[] = new Task[cnt];        for (int i = 0; i < cnt; ++i)      tasks[i] = new Task(mailbox, flag, i);        TestTimedWait test = new TestTimedWait(tasks);    test.run();          // wait for mailbox to fill up    mailbox.await();        // display mail    for (int i = 0; i < cnt; ++i)      System.out.println("main: " + mailbox.messages[i] + " replied");        // pause to allow tasks to queue up on flag    System.out.println("main: sleeping");    try { Thread.currentThread().sleep(1000); } catch (InterruptedException e) {}    System.out.println("main: running");        // release tasks waiting on flag, letting them terminate    flag.set();        // wait for them to terminate    for (int i = 0; i < cnt; ++i) {      System.out.println("main: joining " + tasks[i].getTaskName());      try {        tasks[i].join();      } catch (InterruptedException e) {      }    }    System.out.println("main: bye");  }