2

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?

Community
  • 1
  • 1

1 Answers1

0

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.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Could it be some concurrency problem with my Task? If this was the case, would the worker be able to proceed to SUCCEEDED state? Is there any sources that outlines reasons for why a cancel() would fail? – PolarCareBear Aug 14 '15 at 13:37
  • I don't know if there are any issues with your code, you would need to edit your question to provide an [MCVE](http://stackoverflow.com/help/mcve) for somebody to verify that. [javafx-src.zip is included in the Oracle Java 8 JRE](http://stackoverflow.com/questions/13553375/where-can-i-download-the-javafx-2-2-source-code/), you can investigate the source code to determine some of the reasons for it's behavior. – jewelsea Aug 14 '15 at 17:58