/**
   * Get instance of specified AbortProvoker, inflate associated monitor if needed and then invoke
   * forceAbort method in a loop.
   *
   * <p>Usage: AbortProvoker &lt;AbortType name&gt; [&lt;inflate monitor&gt [&lt;iterations&gt; [
   * &lt;delay&gt;]]]
   *
   * <p>Default parameters are:
   *
   * <ul>
   *   <li>inflate monitor = <b>true</b>
   *   <li>iterations = {@code AbortProvoker.DEFAULT_ITERATIONS}
   *   <li>delay = <b>0</b>
   * </ul>
   */
  public static void main(String args[]) throws Throwable {
    Asserts.assertGT(args.length, 0, "At least one argument is required.");

    AbortType abortType = AbortType.lookup(Integer.valueOf(args[0]));
    boolean monitorShouldBeInflated = true;
    long iterations = AbortProvoker.DEFAULT_ITERATIONS;

    if (args.length > 1) {
      monitorShouldBeInflated = Boolean.valueOf(args[1]);

      if (args.length > 2) {
        iterations = Long.valueOf(args[2]);

        if (args.length > 3) {
          Thread.sleep(Integer.valueOf(args[3]));
        }
      }
    }

    AbortProvoker provoker = abortType.provoker();

    if (monitorShouldBeInflated) {
      provoker.inflateMonitor();
    }

    for (long i = 0; i < iterations; i++) {
      AbortProvoker.verifyMonitorState(provoker, monitorShouldBeInflated);
      provoker.forceAbort();
    }
  }
Пример #2
0
  /**
   * Usage: BusyLock [ &lt;inflate monitor&gt; [ &lt;timeout&gt; ] ]
   *
   * <p>Default values are:
   *
   * <ul>
   *   <li>inflate monitor = {@code true}
   *   <li>timeout = {@code BusyLock.DEFAULT_TIMEOUT}
   * </ul>
   */
  public static void main(String args[]) throws Exception {
    int timeoutValue = BusyLock.DEFAULT_TIMEOUT;
    boolean inflateMonitor = true;

    if (args.length > 0) {
      inflateMonitor = Boolean.valueOf(args[0]);

      if (args.length > 1) {
        timeoutValue = Integer.valueOf(args[1]);
      }
    }

    BusyLock busyLock = new BusyLock(timeoutValue);

    if (inflateMonitor) {
      AbortProvoker.inflateMonitor(busyLock.monitor);
    }

    Thread t = new Thread(busyLock);
    t.start();
    busyLock.test();
    t.join();
  }
 /**
  * Inflates monitor used by this AbortProvoker instance.
  *
  * @throws Exception
  */
 public void inflateMonitor() throws Exception {
   AbortProvoker.inflateMonitor(monitor);
 }