Package winterwell.utils

Examples of winterwell.utils.TimeOut


   * Wraps {@link #run()} with timing, thread-naming, and capturing std-out
   * (if set to do so)
   */
  @Override
  public final V call() throws Exception {
    TimeOut timeOut = null;
    try {
      if (status == QStatus.CANCELLED)
        throw new CancellationException();
      start = new Time();
      // set a timer running
      // - can lead to InterruptedExceptions
      if (maxTime > 0) {
        timeOut = new TimeOut(maxTime);
      }
      // assert runner != null;
      status = QStatus.RUNNING;
      thread = Thread.currentThread();
      // Set the thread name (but keep it short)
      // This will always be reset to Done: or Error: by the end of the
      // method call
      thread.setName(StrUtils.ellipsize(name == null ? toString() : name,
          32));
      if (captureStdOut) {
        sysOut = new SysOutCollectorStream();
      }

      // run!
      output = run();

      end = new Time();
      status = QStatus.DONE;
      thread.setName(StrUtils.ellipsize("Done: " + thread.getName(), 32));
      return output;
    } catch (Throwable e) {
      status = QStatus.ERROR;
      if (runner != null) {
        runner.report(this, e);
      }
      thread.setName(StrUtils.ellipsize("Error: " + thread.getName(), 32));
      // There's not much point throwing an exception from within an
      // executor
      // - but it's useful in debugging.
      throw Utils.runtime(e);
    } finally {
      if (timeOut != null) {
        timeOut.cancel();
      }
      if (runner != null) {
        runner.done(this);
      }
      // drop references
View Full Code Here

TOP

Related Classes of winterwell.utils.TimeOut

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.