public void cancel() {

    this.stateLock.lock();

    try {

      if (this.state == RunnableProcessState.RUNNING) {
        this.process.destroy();
        if (!this.doneCond.await(DESTROY_WAIT_TIME, TimeUnit.MILLISECONDS)) {
          LOG.log(Level.FINE, "{0} milliseconds elapsed", DESTROY_WAIT_TIME);
        }
      }

      if (this.state == RunnableProcessState.RUNNING) {
        LOG.log(Level.WARNING, "The child process survived Process.destroy()");
        if (OSUtils.isUnix() || OSUtils.isWindows()) {
          LOG.log(Level.WARNING, "Attempting to kill the process via the kill command line");
          try {
            final long pid = readPID();
            OSUtils.kill(pid);
          } catch (final IOException | InterruptedException | NumberFormatException e) {
            LOG.log(Level.SEVERE, "Unable to kill the process.", e);
          }
        }
      }

    } catch (final InterruptedException ex) {
      LOG.log(Level.SEVERE,
          "Interrupted while waiting for the process \"{0}\" to complete. Exception: {1}",
          new Object[] {this.id, ex});
    } finally {
      this.stateLock.unlock();
    }
  }
public void cancel ( ) { this . stateLock . lock ( ) ; try { if ( this . state == RunnableProcessState . RUNNING ) { this . process . destroy ( ) ; if ( ! this . doneCond . await ( DESTROY_WAIT_TIME , TimeUnit . MILLISECONDS ) ) { LOG . log ( Level . FINE , "{0} milliseconds elapsed" , DESTROY_WAIT_TIME ) ; } } if ( this . state == RunnableProcessState . RUNNING ) { LOG . log ( Level . WARNING , "The child process survived Process.destroy()" ) ; if ( OSUtils . isUnix ( ) || OSUtils . isWindows ( ) ) { LOG . log ( Level . WARNING , "Attempting to kill the process via the kill command line" ) ; try { final long pid = readPID ( ) ; OSUtils . kill ( pid ) ; } catch ( final IOException | InterruptedException | NumberFormatException e ) { LOG . log ( Level . SEVERE , "Unable to kill the process." , e ) ; } } } } catch ( final InterruptedException ex ) { LOG . log ( Level . SEVERE , "Interrupted while waiting for the process \"{0}\" to complete. Exception: {1}" , new Object [ ] { this . id , ex } ) ; } finally { this . stateLock . unlock ( ) ; } }
Cancels the running process if it is running.