pause and resume a thread javafx
<p>I am trying to pause resume a javafx thread, here is service which manage start and pause of thread:</p>

<pre><code>    package fxmlexample;

    import java.awt.MouseInfo;
    import javafx.concurrent.Task;
    import javafx.stage.Stage;
    import javafx.concurrent.ScheduledService;`

public class myThreadService extends ScheduledService&lt;Void&gt;{

    private static int THREAD_LENGTH = 100;
    private boolean runFlag;

    public void start(Stage stage) throws Exception {
        setRunFlag(true);
        this.start();
    }

     @Override protected void succeeded() {
             super.succeeded();
         }


@Override protected void cancelled() {
             setRunFlag(false);
             super.cancelled();
         }


 @Override protected void failed() {
             super.failed();
         }
    public void resume() throws InterruptedException{
        try{
            this.resume();
            setRunFlag(true);
        }
        catch(InterruptedException e){
            System.out.println("error while resuming thread: "+e);
        }
    } 

    public void setRunFlag(boolean flag){
            this.runFlag = flag;
        }

        public boolean getRunFlag(){
            return runFlag;
        }

        @Override
    protected Task&lt;Void&gt; createTask() {
        return new Task() {
            @Override
            protected Object call() throws Exception {
                for (int i = 0; i &lt; THREAD_LENGTH; i++) {
                    if(!getRunFlag()){
                        this.cancel();
                        break;
                    }
                    int mouseX = MouseInfo.getPointerInfo().getLocation().x;
                    int mouseY = MouseInfo.getPointerInfo().getLocation().y;
                    System.out.println("("+mouseX+","+mouseY+")"+getRunFlag());
                }
                Thread.sleep(100);
                return null;
            }
        };
    }        
}
</code></pre>

<p>I read some post which advise to use variable to decide wether thread should stop or continue. My problem is that once thread is running my getRunFlag is always returning true even if pause() is trigered. So thread continue to run.
Is there a way to get a specific running thread and then safely kill it ?</p>