write a program in java for thread interrupt


class MyThread1 implements Runnable {

  public void run() {
    try {
      Thread.sleep(4000);
    } catch (Exception exc) {
      System.out.println(Thread.currentThread().getName()
          + " is interrupted.");
    }
    System.out.println(Thread.currentThread().getName() + " is exiting.");
  }
}

public class ThreadInterrupt1 {
  public static void main(String args[]) throws Exception {
    Thread th1 = new Thread(new MyThread1(), "First Thread");
    Thread th2 = new Thread(new MyThread1(), "Second Thread");
    th1.start();
    Thread.sleep(2000);
    th1.interrupt();
    th2.start();
    Thread.sleep(5000);
    th2.interrupt();
  }
}
write a program in java for thread interrupt Reviewed by Rejin Paul on 1:28 AM Rating: 5

No comments:

Post Your comments,Views and thoughts Here, Give Us Time To Respond Your Queries

Contact Form

Name

Email *

Message *

Powered by Blogger.