Re: CompletableFuture.cancel vs Future.cancel bug?
Doug Lea via Concurrency-interest <[email protected]> Sun, 23 Aug 2020 16:15:42 -0400
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <[email protected]> |
On 8/23/20 9:30 AM, Sergi Vladykin wrote:
>
>
> Yes, my interpretation was exactly "successful attempt" == "return
> true", "failed attempt" == "return false". Would be nice to have this
> spec improved.
See draft update below, that also tries to clarify mayInterruptIfRunning.
>
> Also, could you please clarify why the decision was made not to have
> CAS-like semantics for CompletableFuture.cancel() while it was clearly
> possible? Maybe there are some hidden benefits I don't see?
>
I don't have a clear recollection (it was during JDK5), but it may have
been a reflection of issues with (concurrent) Collection remove()
methods requiring that the return value indicate that the current call
was responsible for removal, which is sometimes arbitrary and causes
extra expense and complexity. (We considered trying to weaken this, but
didn't.)
... possible javadoc update:
/**
* Attempts to cancel execution of this task. This method has no
* effect if the task is already completed or cancelled, and may
* fail if the task could not be cancelled for any reason. If
* successful, and this task has not started when {@code cancel}
* is called, this task should never run. If the task has already
* started, then the {@code mayInterruptIfRunning} parameter
* determines whether the thread executing this task (if it is
* known by the implementation) should be interrupted in an
* attempt to stop the task.
*
* <p>After this method returns, subsequent calls to {@link
#isDone} will
* always return {@code true}. Subsequent calls to {@link
#isCancelled}
* will always return {@code true} if this method returned {@code
true}.
*
* @param mayInterruptIfRunning {@code true} if the thread
* executing this task should be interrupted (if the thread is
* known to the implementation); otherwise, in-progress tasks are
* allowed to complete
* @return {@code false} if the task could not be cancelled,
* typically because it has already completed; {@code true}
* otherwise. If two or more threads cause a task to be cancelled,
* then at least one of them returns {@code true}.
*/
boolean cancel(boolean mayInterruptIfRunning);
_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest