UI goes not responding in JavaFx

那年仲夏 提交于 2019-12-25 09:40:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!