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

Thread stop() doesn't work when the thread is suspended

XMLWordPrintable

    • 1.1
    • sparc
    • solaris_2.3
    • Not verified

      The java interpreter got stuck(didn't exit) when there is a suspended thread.
      The call to t.stop() didn't kill the thread t when the thread t is suspended.
      There is no exception to be thrown when calling t.resume() after invoking
      t.suspend() and t.stop().

      ---code---

      class jotter extends Thread {
        int count = 0;

        jotter(String n)
        {
          super(n);
        }

        public int getcount()
        {
          System.out.println("The current thread is : " + Thread.currentThread().getName());
          return count;
        }

        public void run() {

          while ( true ) {
            count++;
            System.out.println(count + ": I will be suspended.");

            // computation ...
            for(int j =0; j < 50000; j++) ;

            Thread.currentThread().sleep(5);
            System.out.println(count + ": I'm back");
          }
        }
      }

      class threadtest12 {
        public static void main(String args[]) {
          int i= 0;
          jotter jt = new jotter("jotter");

          jt.start();

          Thread.currentThread().setName("mainthread");
          // let the jotter run
          Thread.currentThread().yield();

          // idle
          for(int j=0; j < 10000; j++) ;

          // resume the child thread
          jt.suspend();

          Thread.currentThread().sleep(100);

          //we still call the method jt.getcount() though
          //thread jt is suspended
          System.out.println(jt.getcount());
       
          // if we don't resume thread jt here, the call
          // jt.stop() won't take effect.

      // jt.stop();
       
          Thread.currentThread().sleep(100);
       
          System.out.println("ok");

        }
      }
       

            tlindholsunw Timothy Lindholm (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: