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

unexpected behaviour of Object.wait method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P5 P5
    • None
    • 1.4.2
    • core-libs
    • sparc
    • solaris_8



      Name: ipR10067 Date: 11/12/2002



      The following example shows unexpected behaviour of Object.wait method:

      public class hang extends Thread {
       
          public static void main(String argv[]) {
              Thread thread = new hang();

              System.out.println("prepare to hang !!");
              try {
                  synchronized (thread) {
                      thread.start(); /*1*/
           thread.wait(); /*2*/
                  }

                  System.out.println("test should be hung !!!");

              } catch (InterruptedException e) {
                  System.out.println("InterruptedException" + e);
              }
          }
      }

      logs:

      >java -version
      java version "1.4.2-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b06)
      Java HotSpot(TM) Client VM (build 1.4.2-beta-b06, mixed mode)
      >java -cp . hang
      prepare to hang !!
      test should be hung !!!
      -------------------------------------------------------------
      According to description of the Object.wait method

      "Causes current thread to wait until another thread invokes
      the notify() method or the notifyAll() method for this object."

      the test should hang up at the point /*2*/ because there are no invocation of
      the notify() method nor the notifyAll() method for the object "thread".

      It looks like that some hidden thread invokes the notify() or
      notifyAll() methods for the object "thread".

      If the line /*1*/ is commented out then the test hangs as expected.

      ======================================================================

            jjb Josh Bloch
            ipsunw Ip Ip (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: