Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail NNTP-Posting-Date: Tue, 31 May 2011 09:14:02 -0500 Date: Tue, 31 May 2011 07:14:02 -0700 From: Peter Duniho User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; 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: Lines: 29 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 50.46.118.188 X-Trace: sv3-dfw/noQMyKEPKOzckB7ZQIwyKe7AZlK5ZGlpzHxdfKcSjZ/flcKay+cglOgkWMST+hE8/4Y1GFAy8qv!rSS5Wl2wUhXFy/LBxqsnVsP8MSfzWP1A6nAgzt8LeJDU6WRzuAarxTY2gIiBm6ZsHdq9RxNfc7q8!cg1+fCIbiRjfxkG74RHw8Wr/Lt83uNhVTMtvMhM7VvU= X-Complaints-To: abuse@iinet.com X-DMCA-Complaints-To: abuse@iinet.com 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: 2698 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4794 On 5/31/11 7:00 AM, Tom Anderson wrote: > [...] > A Future looks ideal - it provides synchronisation, and a > value, and provides the same value to all requesters once it's > delivered, and also handles failure and cancellation. But i don't see an > easy way to make one for a simple value. There is FutureTask, but that > seems more geared to wrapping Callable and Runnable. > > Any suggestions? Personally, I'd just use the Object.wait() and Object.notifyAll() methods. I also don't see why FutureTask doesn't work for you (Future is just an interface…FutureTask implements that interface); just because you have more processing to do after delivering the value, that doesn't necessarily mean that processing has to occur in the same thread, does it? (Alternatively, you could provide a custom implementation of Future that doesn't wrap a Runnable like FutureTask, letting your thread continue even after delivering the Future…but such an implementation would be more complicated than just using the wait()/notifyAll() pattern, so probably not worth the effort unless you expected to reuse the implementation a lot). It would be helpful if you could elaborate on why neither of those simple, straightforward approaches satisfy your goals. Pete