[concurrency-interest] More Javadoc problems

Peter Levart peter.levart at gmail.com
Fri Dec 19 17:15:33 EST 2014


On 12/19/2014 10:30 PM, cowwoc wrote:
> On 19/12/2014 4:10 PM, Peter Levart wrote:
>> If you want to change the exceptional OR nonexceptional outcome of 
>> preceeding stage, then use handle() instead of whenComplete().
>
> I can't.
>
> If you handle() and attempt to re-throw the same exception, you will get:
>
>     unreported exception Throwable; must be caught or declared to be 
> thrown

This problem has been discussed before on the list. See here:

http://cs.oswego.edu/pipermail/concurrency-interest/2014-August/012907.html

The basic principle is to wrap the Throwable as a cause into a 
CompletionException.

>
> I agree that whenComplete() is meant to act as a finally block (which 
> removes the need to do this funky casting). What I don't like is that 
> join() returns without waiting for the result of whenComplete(). If 
> the case of a real try-finally block, the code after the block does 
> not execute after finally completes. I am trying to implement the same 
> behavior here.
>
> What should I be doing instead?
>
> Gili

If you join the 1st CompletableFuture (cf1), it returns when cf1 
completes. The completion of cf1 triggers execution of the 2nd stage 
(cf2). If you join the cf2, it will return when cf2 (the whenComplete 
block) completes. Note that the program executes the stages in a 
background thread (requested with supplyAsync for the 1st stage). The 
same thread then executes following non-async stages. You are joining in 
main thread.

Regards, Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20141219/f2405773/attachment.html>


More information about the Concurrency-interest mailing list