Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!xlned.com!feeder1.xlned.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!209.197.12.246.MISMATCH!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 01 Jun 2011 11:01:27 -0500 Date: Wed, 01 Jun 2011 09:01:28 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Making one or more threads wait for another to produce a value or fail References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <_IadnUg5nPvK_3vQnZ2dnUVZ_q-dnZ2d@earthlink.com> Lines: 44 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.199.144 X-Trace: sv3-t2BFt8ygy3o5IvoJUQm1idWKsPTC5BtF1YiXYBPsRmFmzPnAm41xaAdpibnXYmaJnEPGyDGiKQbmGB5!PyFw1IwWVllJl+DqXsIIoGxcecYEuLZvdWZHC+bBfRJXhlEuDPbqUXz+Az4ZhO8r2nK47DC1dCjg!slZIKzRFOvM5rDX5fX9h/G2rV9TV9kBQ4ff/P1M4p6mcPpU= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3825 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4860 On 6/1/2011 7:18 AM, Peter Duniho wrote: > On 5/31/11 9:37 PM, Patricia Shanahan wrote: >> On 5/31/2011 8:45 PM, Peter Duniho wrote: .... >>> Spurious wakeup, yes (why people continue to tolerate that in >>> Java, I have no idea…plenty of other APIs with concurrency >>> support don't have that trouble). >> >> I don't continue to tolerate spurious wake-ups in Java. My view of >> wait and notify is that they are low level primitives that I used >> as long as they were all we had. Why not use e.g. CountDownLatch? > > That's certainly one way to look at it. But you are still > "tolerating" spurious wake-ups in the sense in which I wrote that. > Why should the language _force_ you to avoid what would otherwise be > perfectly good program statements? > > In a language like Java, there really shouldn't be any such thing as > "low level primitives", except those that are still useful and easy > to use. The entire programmer-available surface should be usable > as-is. Yes, it's great when the libraries offer an abstraction that > more closely fits ones needs, but for there to be statements in Java > that pretty much just _always_ need working-around through the use of > some helper class doesn't make sense to me. It would definitely have been better if java.util.concurrent had been available in release 1.1. Nobody would have been forced to use wait-notify. It might even have been better to treat wait-notify as com.sun package stuff. That would have avoided misleading people into using it directly, in preference to perfectly suitable and far more convenient java.util.concurrent features, but might have inhibited experimentation with alternative features at the next level up. > Spurious wake-ups offer no benefit to the user (i.e. the programmer) > and are a symptom of implementation detail bleeding through into the > higher-level language. It's a strange anomaly in what is otherwise > normally a very helpful and relatively simple (in a good way) > high-level language. I agree. That is one reason why I recommend ignoring wait-notify in favor of java.util.concurrent unless you are implementing something with special requirements that are not met by any of the existing java.util.concurrent classes. Patricia