public static void main(String[] args) throws InterruptedException {
   Thread thread = new Thread(new MyRunnable());
   thread.start();
   Thread.sleep(1000);
   thread.destroy();
   System.out.println("Existing application");
 }
Example #2
1
  /** @throws TimeoutException */
  @SuppressWarnings("deprecation")
  private void waitFor(final ChannelExec channel) throws TimeoutException {
    // wait for it to finish
    Thread thread =
        new Thread() {
          public void run() {
            while (!channel.isClosed()) {
              try {
                sleep(RETRY_INTERVAL);
              } catch (InterruptedException e) {
                // ignored
              }
            }
          }
        };

    thread.start();
    try {
      thread.join(maxwait);
    } catch (InterruptedException e) {
      // ignored
    }

    if (thread.isAlive()) {
      thread.destroy();
      throw new TimeoutException("command still running");
    }
  }
 @Override
 public void destroy() {
   // TODO Auto-generated method stub
   super.destroy();
   this.interrupt();
   // null
 }