UI goes not responding in JavaFx

2019-09-15 12:03发布

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

2条回答
太酷不给撩
2楼-- · 2019-09-15 12:34

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

查看更多
【Aperson】
3楼-- · 2019-09-15 12:41

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();  
    }  
}
查看更多
登录 后发表回答