Tuesday 15 March 2011

java - JavaFX stop threads -


I write a program that requires information from a server. I use asynchronous thread to complete it but when a user clicks on another item, a new thread begins. If the first issue of a network has not yet ended due to the issue, the second thread ends and the UI sets the information. Then the first one ends and writes it again. So how can I stop the first thread when the user clicks on another item?

I found this:

  thread asyncThread = new thread (function); AsyncThread.start ();   

But what I can see in the thread object, there is no way to stop the thread (only the deprecated .stop ()), but I do not want to use the stuff to dislike service in JavaFX It is recommended to use, a service provides a method, such as stop (), cancel (), restart () ... See my answer to show how to use the service.

No comments:

Post a Comment