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

AWTThreadIssues.html contains example that throws IllegalMonitorStateException

XMLWordPrintable

    • b49
    • x86
    • windows_xp
    • Verified

      A DESCRIPTION OF THE PROBLEM :
      There is an example given at the bottom of AWTThreadIssues.html that indicates how to keep the JVM running after the application has made all components undisplayable, by creating a daemon thread and waiting on a private monitor.

      The call to wait() on the lock object is not inside a block that synchronizes on the object. Therefore the current thread does not have a lock on the specified monitor and a java.lang.IllegalMonitorStateException is thrown.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      <...>
      Runnable r = new Runnable() {
      public void run() {
      Object o = new Object();
      try {
      synchronized(o) {
      o.wait();
      }
      } catch (InterruptedException ie) {
      }
                  }
      };
      Thread t = new Thread(r);
      t.setDaemon(false);
      t.start();
      <...>
      ACTUAL -
      <...>
      Runnable r = new Runnable() {
      public void run() {
      Object o = new Object();
      try {
      o.wait();
      } catch (InterruptedException ie) {
      }
                  }
      };
      Thread t = new Thread(r);
      t.setDaemon(false);
      t.start();
      <...>

      URL OF FAULTY DOCUMENTATION :
      <jdk-root>/docs/api/java/awt/doc-files/AWTThreadIssues.html
      ###@###.### 2005-07-13 23:43:21 GMT

            art Artem Ananiev (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: