[concurrency-interest] We need to add blocking methods to CompletionStage!

David Holmes davidcholmes at aapt.net.au
Sun Sep 25 11:45:44 UTC 2016

I think that was meant to read “After this method returns _true_, subsequent calls …”




From: Concurrency-interest [mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Viktor Klang
Sent: Sunday, September 25, 2016 9:03 PM
To: Martin Buchholz <martinrb at google.com>
Cc: concurrency-interest <concurrency-interest at cs.oswego.edu>; core-libs-dev <core-libs-dev at openjdk.java.net>
Subject: Re: [concurrency-interest] We need to add blocking methods to CompletionStage!




On Sun, Sep 25, 2016 at 12:34 PM, Viktor Klang <viktor.klang at gmail.com <mailto:viktor.klang at gmail.com> > wrote:



On Sat, Sep 24, 2016 at 10:41 PM, Martin Buchholz <martinrb at google.com <mailto:martinrb at google.com> > wrote:

No one is suggesting we add cancel to CompletionStage - I agree that would break users, by making an immutable interface mutable. 




This also means that CompletionStage cannot extend Future.




I also would not want to have a toFuture method that would return a j.u.c.Future, because of misfit Future.cancel.


Would you mind elaborating here? According to the cancel method spec on Future it is completely fine for it to be a no-op which always returns false:


"This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason."


Source: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html


There's an interesting (read: weird) spec clause in cancel:


"After this method returns, subsequent calls to isDone() will always return true. Subsequent calls to isCancelled() will always return true if this method returned true."


That clause is in contradiction with the previously quoted line.





  If we are adding cancel, then it will be to make a new interface, such as the suggested CancellableCompletionStage.


I also agree that CompletionStage does *not* represent "a running task of sorts", j.u.c. Future specs are still confusing in that way due to FutureTask heritage.





On Thu, Sep 22, 2016 at 7:51 PM, James Roper <james at lightbend.com <mailto:james at lightbend.com> > wrote:

For example, we often cache futures and return them from a libraries API, if a client could cancel a future, that would break everything else that received that future.


On Fri, Sep 23, 2016 at 2:24 PM, Viktor Klang <viktor.klang at gmail.com <mailto:viktor.klang at gmail.com> > wrote:

PPS: A misunderstanding is that CompletionStage represents a running task of sorts, one that can be cancelled etc. This is not the case.











More information about the core-libs-dev mailing list