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

Documentation (javadoc/ JVM spec): reason for Object.notify requires a lock

XMLWordPrintable

    • x86
    • windows_xp

      A DESCRIPTION OF THE PROBLEM :
      First, thank you guys for giving us Java :)

      Still, could you please consider a documentation request for the JVM spec:
      It *is* well documented that "object.notify()" can only be invoked by the monitor owner. Namley, one must call "synchronized(object)", otherwise it's an IllegalThreadStateException.

      However, there appears to be no documentation as to the *motivation* or reason for it. To the best of my knowledge, no explanation is offered (not in the JVM spec 2nd edition, nor in the javadoc of Object.notify).

      I get the impression few people in the *world* know the reason ;)
      I've consulted various university professors, expert forums, CTO's, even a couple of Sun employees ... and no luck.

      They all noted it's logically *likely* that if someone's calling "notify", they have probably just modified some shared data, in which case they're likely to be owning the lock anyway.
      However, the fact it's *logically* likely, doesn't necessarily explain why it's mandated *technically* (even if that is the motivation, people might be interested in having it confirmed, IMHO).

       Thanks again & keep up the great work.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A short explanation for why "object.notify" requires synchronization.
      Could be a couple of lines (or, if that requires a more profound discussion, a relevant link ?)
      ACTUAL -
      JVM spec
      (http://java.sun.com/docs/books/vmspec/2nd-edition/html/Threads.doc.html#21294):
      "The method wait should be invoked for an object only when the current thread (call it T ) has already locked the object's lock. "

      Java doc of Object.notify
      (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html):
      "This method should only be called by a thread that is the owner of this object's monitor"

      URL OF FAULTY DOCUMENTATION :
      http://java.sun.com/docs/books/vmspec/2nd-edition/html/Threads.doc.html#21294
      ###@###.### 2005-05-17 09:34:36 GMT

            Unassigned Unassigned
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: