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

2015-06-03 Thread Brian Goetz
The performance issue here is mostly a red herring. The reason notify() is not synchronized has much more to do with correctness; when you "forget" to wrap your notify call with lock acquisition, it is almost always a bug. (The rest of this explanation is probably clearer if you've read JCiP

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

2015-06-03 Thread Andreas Lundblad
On Sun, May 31, 2015 at 02:31:25PM +1000, David Holmes wrote: > >As I recently fell into the trap of forgetting the synchronized block > >around a single notifyAll(), I believe, the current situation is just > >errorprone. > > How is it errorprone? You forgot to acquire the lock and you got an > I

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

2015-05-30 Thread David Holmes
On 30/05/2015 2:48 AM, Ulf Zibis wrote: Thanks for your hint David. That's the only reason I could imagine too. Can somebody tell something about the cost for recursive lock acquisition in comparison to the whole call, couldn't it be eliminated by Hotspot? There are a number of fast paths relat

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

2015-05-29 Thread Ulf Zibis
Thanks for your hint David. That's the only reason I could imagine too. Can somebody tell something about the cost for recursive lock acquisition in comparison to the whole call, couldn't it be eliminated by Hotspot? As I recently fell into the trap of forgetting the synchronized block around a

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

2015-05-28 Thread David Holmes
On 29/05/2015 2:08 AM, 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. Because, as

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

2015-05-28 Thread David M. Lloyd
Since most of the time you have to hold the lock anyway for other reasons, I think this would generally be an unwelcome change since I expect the cost of recursive lock acquisition is nonzero. On 05/28/2015 11:08 AM, Ulf Zibis wrote: Hi all, in the Javadoc of notify(), notifyAll() and wait(..

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

2015-05-28 Thread Aleksey Shipilev
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. W

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

2015-05-28 Thread Vitaly Davidovich
What would synchronized on that method help with? Typically you do something while holding the lock and then notify while still holding the lock. sent from my phone On May 28, 2015 12:09 PM, "Ulf Zibis" wrote: > Hi all, > > in the Javadoc of notify(), notifyAll() and wait(...) I read, that this

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

2015-05-28 Thread Ulf Zibis
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. Also I think, the following note should be moved f