Java FX - How to terminate a ScheduledService
<p>I wrote a little code to download some files from internet..if user click on cancel button this must be stopped..i use the cancel() method for do it..but it didn't work.</p>

<pre><code>ScheduledService&lt;Object&gt; service = new ScheduledService&lt;Object&gt;() {
            protected Task&lt;Object&gt; createTask() {
                return new Task&lt;Object&gt;() {
                    protected Object call() {
                        if (checkinternet()) {
                            downloadFiles();
                        }
                        return null;
                    }

                };
            }
        };
        service.start();
</code></pre>

<p>In buttons action event handler i called cancel method for stop service..
but it wasn't successful..</p>

<pre><code>service.cancel();
</code></pre>

<p>How do i do that...</p>