JavaFX UI hangs



我正在ecilpse下编写一个JavaFX程序,它在我的本地机器上运行良好,即我可以在导出后执行可运行的jar。但是,当我将可执行 jar 放到另一台机器时,UI 没有响应。以下是我启动javaFX程序的代码。

 @Override
       public void start(Stage primaryStage) {
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
           @Override
           public void handle(WindowEvent e) {
              Platform.exit();
              System.exit(0);
           }
        });
           this.primaryStage = primaryStage;
           this.primaryStage.setTitle("Server Simulator");
           context = new ClassPathXmlApplicationContext("classpath:PrTrSim.xml");
           this.displayQueue = (LinkedBlockingQueue<Message>) context.getBean("displayQueue");
           this.userInputQueue = (LinkedBlockingQueue<Message>) context.getBean("userInputQueue");
           this.outgoingQueue = (LinkedBlockingQueue<Message>) context.getBean("outgoingQueue");
           this.incomingQueue = (LinkedBlockingQueue<Message>) context.getBean("incomingQueue");
           addQueue.add(this.displayQueue);
           addQueue.add(this.outgoingQueue);
           addQueue.add(this.incomingQueue);
           initRootLayout();
           showSimOverview();
       }
   public static void main(String[] args) {  
        launch(args);
    }

PrTrSim.xml用于初始化后面运行的两个组件(messageProcessor和SocketIO读取器)。这 4 个阻塞队列用于接收和处理消息。

为了避免阻塞主线程,您应该使用 JavaFX 的任务或服务概念,如下所述:http://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm

最新更新