How do I kill the JavaFX Platform thread without having to call System.exit()?

Shane Gillis :

I'm writing a plugin tool using JavaFX for our Flagship Application (at work). The Flagship App has a Java client that uses Swing, and it allows the user to execute macros written in Java, or install plugins written with Java.

Note, these macros/plugins can run on their own and are not dependent upon the Java client, so there is no need to place JavaFX components into a JFXPanel.

The problem we've been having is one of debugging convenience. We run the macro or plugin that uses JavaFX, and after we kill it (using stop() and Platform.exit() ), we have to completely restart the Flagship App Java client (i.e. the JVM) before we can re-run the JavaFX macro/plugin, thanks to the whole "Application launch must not be called more than once" error. The Flagship App loads relatively quickly, but it still needs a minute or two to fully load and open a new file (can't run a macro or plugin without an open file).

So I've seen a few suggestions to place subsequent calls to Application.launch() into a runLater call, or to use the Executor service, but none of these seems to really get at what I need, since the Platform thread appears to be killed off (JavaFX GUI closes properly, and the thread vanishes from the list of running threads). It's almost as if the JVM has a boolean that gets set to true when you call Application.launch(), so that you can't restart a JavaFX app without killing the JVM.

I need to be able run a JavaFX Application multiple times on the same JVM. So is it possible to do that?

TornadoFX Fan :

Are you able to define the JavaFX macros using Stage rather than Application? If so, this video coordinates the shutdown of a main Swing app that brings up multiple JavaFX windows.

https://www.youtube.com/watch?v=1cobvRlRHic

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=109811&siteId=1