Also available as Wait.java

/**
 * Title: Wait
 * Description: Exception handling in a loop.
 *   We can't resume, but we can keep trying until the
 *   problem is resolved.
 * @author hollingd@cs.rpi.edu
 */


public class Wait {

    public static void main(String[] args) {
        boolean done=false;
        int seconds=0;

        try {
            seconds = Integer.parseInt(args[0]);
        } catch (Exception e) {
            System.out.println("Please specify the number of seconds");
            System.exit(1);
        }

        long initialtime = System.currentTimeMillis();

        while (!done) {
            try {
                if (System.currentTimeMillis()-initialtime<seconds*1000)
                    throw new Exception("Not Yet - keep trying");
                done=true;
            } catch (Exception e) {
                System.out.println(e);
            }
        }
        System.out.println("Done!\n");
    }
}