I am trying to cancel my JavaFX Service
using the cancel()
method.
Before I call cancel()
, I check the Worker
state.
System.out.println(service.getState());
System.out.println(service.cancel());
The cancel()
method persistently fails when the Worker
is in the SCHEDULED
state. cancel()
returns false, and the Worker
proceeds to the RUNNUNG
state, before terminating as SUCCEEDED
.
I cant find anything in the docs about cancel()
not affecting a SCHEDULED
Worker
. Is this normal behaviour?
If this is the case, then you should file a bug report, as the behavior you describe directly contradicts the specified behavior in the Worker.State
javadoc.
A Worker may be cancelled when READY, SCHEDULED, or RUNNING, in which case the final status will be CANCELLED. When a Worker is cancelled in one of these circumstances it will transition immediately to the CANCELLED state.
Could it be some concurrency problem with my Task?
I want somebody to answer questions about potential issues in your code, you need to edit your question to provide an MCVE.
Is there any sources that outlines reasons for why a cancel() would fail?
javafx-src.zip is included in the Oracle Java 8 JRE, you can investigate the source code to determine some of the reasons for it's behavior.