Merge in fix for Glassfish-21175

Hi David, 
this suffers from spurious wake-ups. you should always call wait() from inside a loop. see this for details:  http://www.devguli.com/blog/eng/spurious-wakeup/