public class MonitorUsedDeflationThresholdTest {
    public static final int DELAY_SECS = 10;
    public static int inflate_count = 0;

    public static void do_work(int count) {
        System.out.println("Recursion count=" + count);
        if (count > inflate_count) {
            System.out.println("Exceeded inflate_count=" + inflate_count);

            System.out.println("Delaying for " + DELAY_SECS + " secs.");
            try {
                Thread.sleep(DELAY_SECS * 1000);
            } catch (InterruptedException ie) {
                // ignore InterruptedException
            }
            System.out.println("Done delaying for " + DELAY_SECS + " secs.");
            return;
        }

        Object obj = new Object();

        synchronized(obj) {
            try {
                obj.wait(1);  // force inflation
            } catch (InterruptedException ie) {
                // ignore InterruptedException
            }
            do_work(count + 1);
        }
    }

    public static void usage() {
        System.err.println("Usage: java " +
                           "MonitorUsedDeflationThresholdTest inflate_count");
    }

    public static void main(String[] args) {
        if (args.length != 1) {
            usage();
            throw new RuntimeException("ERROR: " +
                                       "missing inflate_count parameter.");
        }

        try {
            inflate_count = Integer.decode(args[0]);
        } catch (NumberFormatException nfe) {
            usage();
            throw new RuntimeException("ERROR: '" + args[0] +
                                       "': bad inflate_count.");
        }

        System.out.println("Hello from MonitorUsedDeflationThresholdTest!");
        System.out.println("inflate_count=" + inflate_count);

        do_work(1);
    }
}
