问题
We have application which is Integrated with Network device for performance and tuning related functionalities.
We are using JavaFx For UI, when ever i connect to Network device,for login and get responses the UI Show "Not Responding".
could any one suggest how to over come the issue.Login screen shows not respongding
回答1:
The UI goes not responding because the program is connecting to the network device and the UI is being run in the same Thread
. You need to start a new Thread
to connect network device. When UI and connection to network device are in two different threads, the UI will not freeze.
class YourThread extends Thread{
public void run(){
// Your code to connect to network device
}
public static void main(String args[]){
YourThread thread = new YourThread();
thread.start();
}
}
回答2:
Any I/O done over a slow and unstable channel such as (but not limited to) a network is bound to give not responding user interfaces. Therefore any significant I/O should be done in a separate thread.
Some of the options you have are:
- Start a new thread
- Create a JavaFX Task or Service, provides easiest integration in user feedback and task progress feedback
- Use java 8's CompletableFuture, or a chain of these
- Use reactive programming (which is CompletableFuture more or less)
See also: Concurrency in JavaFX
来源:https://stackoverflow.com/questions/43867073/ui-goes-not-responding-in-javafx