Why isn't Object.notify() a synchronized method? (original) (raw)
Aleksey Shipilev aleksey.shipilev at oracle.com
Thu May 28 16:28:17 UTC 2015
- Previous message: Why isn't Object.notify() a synchronized method?
- Next message: Why isn't Object.notify() a synchronized method?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Why isn't Object.notify() a synchronized method?
- Next message: Why isn't Object.notify() a synchronized method?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]