JDK-4148126 : Thread.stop() doesn't prevent thread being started later
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1998-06-12
  • Updated: 1998-06-19
  • Resolved: 1998-06-19
Related Reports
Duplicate :  
Relates :  
Description

Name: mf23781			Date: 06/12/98


The Java Language Specification and the JDK documentation clearly 
states that if  a thread that has been stopped with Thread.stop() 
is subsequently started with Thread.start(), the thread terminates 
immediately. 
However, in the current implementation of the JDK, the thread executes 
to completion normally instead of being "terminated immediately". 

//
// In the documentation of Thread.stop(), it states:
//
// "It is permitted to stop a thread that has not yet been started.
//  If the thread is eventually started, it immediately terminates."
//
//
// The following code demonstrates that this specification is not implemented.
// The thread t1 is stopped, then started. It executes to completion and is not
// "terminated immediately", as per the API documentation.
//
// To compile: javac Bug1.java
//


public class Bug1 implements Runnable
{
   public boolean hasRun;

   public Bug1()
   {
      hasRun = false;
   }

   public void run()
   {
      try {
         hasRun = true;
      } finally {
      }
   }

   private static void test()
   {
         Thread   t1;
         Bug1    b1;

         b1 = new Bug1();
         t1 = new Thread(b1);

         t1.stop();
         t1.start();

         try {
            t1.join();
         } catch (InterruptedException e) {
         }

         if (b1.hasRun) {
            System.err.println("failed...t1 executed after a stop()");
         } else {
            System.err.println("passed");
         }
   }

   public static void main(String args[])
   {
      test();
   }
}

This was originally discovered on AIX 1.1.6, but also occurs on NT JDK 1.1.6, 
1.1.7A, 1.2beta4H.
======================================================================

Comments
WORK AROUND Name: mf23781 Date: 06/12/98 The defect raiser has created an alternative implementation of the JLS thread specification that implements the specification reliably. ======================================================================
11-06-2004