The Java Program: Wait.java

  1 // Wait.java
  2 
  3 public class Wait extends Thread {
  4    private int maxcount;
  5    private int current;
  6 
  7    Wait (int maxcount) {
  8       this.maxcount = maxcount;
  9    }
 10 
 11    public int getCount () { return current; }
 12 
 13    public void run () {
 14       for (int count=1; count<=maxcount; count++) {
 15          System.out.println (count + " " + getName());
 16          current = count;
 17       }
 18       System.out.println ("DONE! " + getName());
 19    }
 20 
 21    public static void main (String args[]) throws InterruptedException {
 22       Wait [] handle = new Wait [args.length];
 23       for (int i=0; i<args.length; i++) {
 24          handle[i] = new Wait (Integer.parseInt(args[i]));
 25          handle[i].start();
 26       }
 27       for (int i=0; i<handle.length; i++) {
 28          handle[i].join();
 29          System.out.println ("Join " + handle[i].getName() + "  " +
 30                              handle[i].getCount());
 31       }
 32    }
 33 }