2 Replies Latest reply on Mar 15, 2012 1:54 PM by AjayL

    Interrupt a Thread

      I am testing a small application to interrupt the new child thread created.

      My question is:

      How is t.interrupt() able to interrupt the child thread? Is t the main thread that creates a new child thread?
      So,shoudnt t.interrupt() interrupt the main thread rather than the child thread?
      or am I missing something?
      public class UsingFlagToShutdownThread extends Thread{
           private boolean running = true;
           // Entry point for a child thread.
           public void run() {
               while (running) {
                 try {
                 } catch (InterruptedException ex) {
               System.out.println("Shutting down thread");
             public static void main(String[] args)  throws InterruptedException {
                  UsingFlagToShutdownThread t = new UsingFlagToShutdownThread();
                  t.start();   // Create a Child Thread.
                  t.interrupt();    // How does t.interrupt() interrupt the child thread created?