Re: CompletableFuture.cancel vs Future.cancel bug?
Martin Buchholz via Concurrency-interest <[email protected]> Thu, 20 Aug 2020 10:48:22 -0700
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <CA+kOe0_w1AFsBNO+DourmDgpdj+t1LK3DUih5JzL2Yk2w2ndgA@mail.gmail.com> |
You didn't make it completely clear - I think you're saying that the meaning of the return value from FutureTask.cancel() and CompletableFuture.cancel() are inconsistent. I agree, and this bothers me a little as well. The spec for Future.cancel() includes the word "typically" so arguably there's enough wiggle room. As usual, trying to fix this now will likely cause more trouble than living with it. On Thu, Aug 20, 2020 at 9:28 AM Sergi Vladykin via Concurrency-interest <[email protected]> wrote: > > Investigated further: FutureTask respects the Future.cancel contract, ForkJoinTask does not. > Also Guava AbstractFuture implements cancel correctly. > > Practically this means that users can not rely on the Future.cancel() correctness. > > > On Thu, Aug 20, 2020 at 11:11 AM Sergi Vladykin <[email protected]> wrote: >> >> Hi, >> >> I noticed that the CompletableFuture.cancel method breaks the contract for Future.cancel. >> The spec says "This attempt will fail if the task ... has already been cancelled..." but at the same time CompletableFuture will return true even if someone else has cancelled the future. >> >> I see that it can be workarounded by completeExceptionally(new CancellationException()) but this inconsistency is neither obvious nor even documented and IMO should be fixed. >> >> To be clear I'm extending CompletableFuture.cancel with my own cancellation logic and obviously I want this logic to be executed only once thus using super.cancel() would be wrong. On another hand I want my future to behave consistently with the original CompletableFuture and of course I can emulate that but this all gets ugly... >> >> Please advise. >> >> Sergi >> >> > > _______________________________________________ > Concurrency-interest mailing list > [email protected] > http://cs.oswego.edu/mailman/listinfo/concurrency-interest _______________________________________________ Concurrency-interest mailing list [email protected] http://cs.oswego.edu/mailman/listinfo/concurrency-interest