我正在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 reader).4个阻塞队列用于消息接收和处理。
答案 0 :(得分:1)
为避免阻塞主线程,您应该使用JavaFX任务或服务概念,详见此处:http://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm