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

(thread) Thread sleep that does not sleep (1.2.2)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      Name: stC104175 Date: 06/06/2000


      java version "1.2.2"
      Classic VM (build 1.2.2-L, native threads,
      javacomp)

      the Thread.sleep() method does not sleep after an interrupt () call to the
      thread.

        To demonstrated the problem, the following program read a delay from the
      keybord, set the delay for the sleep and calls interrupt() on the thread.

      This works for 1 or 2 calls to the setDelay(int) method, and no more after : the
      sleep() does not sleep anymore.

      note : the problem occurs with and without the Imprise JIT.

      ///////////////////////////////////////////
      // This program try to change a sleeping delay for a thread
      // and interrupt the thread to take the new delay immediatly.
      // After 2 changes of the delay,
      // the Thread.sleep() DOES NOT SLEEP AT ALL !!!!
      ///////////////////////////////////////////

      import java.io.BufferedReader;
      import java.io.InputStreamReader;
      import java.util.Date;

      public class TestThread implements Runnable {

      // The working thread
      private Thread me = null;

      // sleep delay in seconds
      private int delay;

      public TestThread (int delay) {
      this.delay = delay;
      }

      /**
      * set the delay and try to interrupt the thread
      * in order to take the new delay immediatly
      */
      public void setDelay (int delay) {
      this.delay = delay;
      if (me != null) {
      me.interrupt ();
      }
      }

      public void start () {
      if (me == null) {
      me = new Thread (this);
      me.start ();
      }
      }

      public void stop () {
      if (me != null) {
      Thread current = me;
      me = null;
      current.interrupt ();
      }
      }

      public void run () {
      while (me == Thread.currentThread()) {
      try {
      Thread.sleep (delay * 1000);
      } catch (InterruptedException e) {
      // nothing
      }
      System.out.println ("do something. date:" + new Date().toString());
      }
      }

      public static void main (String args[]) {
      int delay = 10;
      TestThread testThread = new TestThread (10);
      testThread.start ();
      BufferedReader bufferedReader = new BufferedReader(new
      InputStreamReader(System.in));
      while (true) {
      String delayString;
      System.out.println ("enter a delay:");
      try {
      delayString = bufferedReader.readLine ();
      } catch (java.io.IOException ioe) { break; }
      delay = Integer.parseInt(delayString);
      testThread.setDelay (delay);
      }
      }
      }
      (Review ID: 105172)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            psoper Pete Soper (Inactive)
            Reporter:
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: