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

unexpected behaviour of Object.wait method

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_8

      Description



      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.

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: