Javafx Platform.runLater 从不 运行

Javafx Platform.runLater never running

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

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

线程是我的游戏线程。 但它从来没有 运行s 并且我在 Platform.runLater() 中尝试了 System.out.println() 只是为了检查它从不 运行s.

为什么它从来没有 运行,我该如何解决?谢谢。

编辑:只是为了澄清线程肯定已经开始等等,如果我这样做:

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

它输出:

Before Platform.runLater()
After Platform.runLater()

好的,我已经找到解决方法了!

如果您 运行 遇到所有场景都结束的任何情况,管理所有这些的线程就会逐渐消失。为防止这种情况发生,请在 Platform.runLater:

之前添加此行
Platform.setImplicitExit(false);
Platform.runLater(()->System.out.println("Inside Platform.runLater()"));

只要在最后一个场景结束前运行秒,线程就会一直存活,不会运行陷入运行Later()失败的问题!