Why isn't Object.notify() a synchronized method?

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu May 28 16:28:17 UTC 2015


On 05/28/2015 07:08 PM, Ulf Zibis wrote:
> Hi all,
> 
> in the Javadoc of notify(), notifyAll() and wait(...) I read, that this
> methods should only be used with synchronisation on it's instance.
> So I'm wondering, why they don't have the synchronized modifier out of
> the box in Object class.

Well, at least "synchronized" wait() would be very odd, since it
actually relinquishes the monitor. This will pose an interesting
paradox: if wait() is claimed to be synchronized, but notify() requires
acquiring the same monitor, how would any object be notified, ever?

But really, I'd think this serves the purpose of "waking up" with all
the appropriate locking state preserved. E.g. making sure only one
thread owns the object monitor, and it "reenters" back right where it
had left at wait() in the synchronized section.

Thanks,
-Aleksey




More information about the core-libs-dev mailing list