Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4031751

Thread.stop() and Thread.isAlive() have unusual behavior

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1, 1.1.8
    • core-libs
    • sparc
    • solaris_2.5.1

      This behavior exists on Solaris 2.5.1, jdk1.1_Final (not tested on other
      platforms, although I suspect it is more of a design flaw rather
      than a platform bug.)

      Once stop() is called on a Thread, isAlive() returns false although
      the thread continues to run (it has a catch block).

      Subsequent calls to stop() on the same Thread have no effect whatsoever.
      stop() should attempt to stop any thread which is actually running.
      (additionally this is not documented well and is different from interrupt(),
       which has effect whenever called.)

      Sample output:
      > java TSBug
      Thread[Thread-4,5,main] is alive? true
      Thread[Thread-4,5,main] is alive? false
      stopped with java.lang.ThreadDeath
      Thread[Thread-4,5,main] is very much alive!
      Thread[Thread-4,5,main] is alive? false
      slept comfortably.
      Thread[Thread-4,5,main] is very much alive!
      Thread[Thread-4,5,main] is alive? false
      slept comfortably.
      Thread[Thread-4,5,main] is very much alive!


      Input code:


      class TSBug implements Runnable {

        public void run(){
          for(int i=0;i<3;i++){
            try{
      Thread.sleep(2000);
      System.err.println("slept comfortably.");
            } catch(Throwable t){
      System.err.println("stopped with "+t);
            }
            System.err.println(Thread.currentThread()+" is very much alive!");
          }
        }

        public static void main(String[] args) throws Exception {
          Thread t = new Thread(new TSBug());
          t.start();
          System.err.println(t+" is alive? "+t.isAlive());
          for(int i=0;i<3;i++){
            Thread.sleep(1000);
            t.stop();
            System.err.println(t+" is alive? "+t.isAlive());
          }
        }

      }

            kbr Kenneth Russell (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: