Re: CompletableFuture.cancel vs Future.cancel bug?
Sergi Vladykin via Concurrency-interest <[email protected]> Thu, 20 Aug 2020 19:25:51 +0300
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <CA+eZwrHceG0eM6wKbKV6W0v6kOyJ57qKVXmL4z6FRWE_0BspgA@mail.gmail.com> |
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