Javafx Platform.runLater从未运行过

use*_*924 8 java multithreading javafx lwjgl

我基本上希望能够在我的LWJGL/GLFW线程启动后(和内部)启动一个新的Javafx窗口(阶段).我基本上是这样做的:

Thread thread = new Thread(()->Platform.runLater(()->{
    Stage stage = new Stage();
    //Stage setup
    stage.show();
}));
thread.start();
Run Code Online (Sandbox Code Playgroud)

线程是我的游戏线程.但它永远不会运行,我试过一个System.out.println()内部Platform.runLater()只是为了检查它永远不会运行.

为什么它永远不会运行,我该怎么做才能解决它?谢谢.

编辑:只是为了澄清线程已经启动了什么,如果我这样做:

Thread thread = new Thread(()->{
    System.out.println("Before Platform.runLater()");
    Platform.runLater(()->System.out.println("Inside Platform.runLater()"));
    System.out.println("After Platform.runLater()");
});
Run Code Online (Sandbox Code Playgroud)

它输出:

Before Platform.runLater()
After Platform.runLater()
Run Code Online (Sandbox Code Playgroud)

Dra*_*son 29

好的,我找到了解决方案!

如果遇到所有场景都结束的任何情况,管理所有这些的线程就会消失.要防止这种情况发生,请在添加此行之前Platform.runLater:

Platform.setImplicitExit(false);
Platform.runLater(()->System.out.println("Inside Platform.runLater()"));
Run Code Online (Sandbox Code Playgroud)

只要它在最后一个场景结束之前运行,它将使线程保持活动状态,并且你不会遇到runLater()失败的问题!