JDK-6598810 : (thread spec) Thread.yield() not clear with respect to monitor ownership
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2007-08-29
  • Updated: 2011-03-28
  • Resolved: 2007-09-06
Related Reports
Relates :  
Description
Specification of Thread.yield method is pretty brief:

--------------------------
public static void yield()

    Causes the currently executing thread object to temporarily pause and allow other threads to execute.
--------------------------

And it is not clear how this method behave in respect with monitors ownership.

BTW, spec explicitly claims that 'sleep' method does not cause thread to lose monitor ownership.
In this context spec silence about 'Thread.yield' method could be interpreted in following ways:

1. It is up to implementation to determine if monitor ownership is lost or not.
2. Monitor ownership is explicitly lost.

In any case it looks like correct interpretation should be spelled explicitly in spec.

Comments
EVALUATION If a method says nothing about monitor ownership then monitor ownership is unaffected. There is only one method in the entire JDK that affects monitor ownership and that is Object.wait(). The mention that Thread.sleep() does NOT affect monitor ownership was put in as a warning "hey be careful using this if you hold monitors" not as a subtle implication that methods might arbitrarily mess with monitor ownership! We do not want to start documenting that methods do not affect monitor ownership. Other aspects of the yield specification have been updated with 6416721.
06-09-2007