gpt4 book ai didi

java - 由于 OSX 中的其他线程,Platform.exit() 未结束 Javafx

转载 作者:行者123 更新时间:2023-11-30 06:55:11 26 4
gpt4 key购买 nike

我有一个 javafx 8 应用程序,当我想关闭它时,它有多个 Activity 线程,此代码显示 8 个 Activity 线程:

    ThreadGroup group = Thread.currentThread().getThreadGroup();
LOG.debug("Number of active threads = " + group.activeCount());

使用 Platform.exit();Platform.setImplicitExit(true); 并不能让我干净退出。

我尝试在调用 Platform.exit(); 之前或之后终止所有线程,但没有成功。

即使在中断之前将线程设置为守护进程也无法解决问题。

        while (group != null) {
group.setDaemon(true);
group.interrupt();
group = Thread.currentThread().getThreadGroup();
}

此处不能调用 System.exit(0),因为其他应用可以从其他应用内启动或独立启动。

退出前显示的错误是不在 FX 应用程序线程上; currentThread = JavaFX应用程序线程

编辑1:错误的堆栈跟踪:

    ERROR SimpleUncaughtExceptionHandler.java uncaughtException 34     [JavaFX Application Thread] Uncaught exception
java.lang.IllegalStateException: Not on FX application thread; currentThread = JavaFX Application Thread
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236) ~[jfxrt.jar:?]
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423) ~[jfxrt.jar:?]
at javafx.stage.Window.setShowing(Window.java:921) ~[jfxrt.jar:?]
at javafx.stage.Window.hide(Window.java:947) ~[jfxrt.jar:?]
at com.sun.javafx.stage.WindowPeerListener.closed(WindowPeerListener.java:100) ~[jfxrt.jar:?]
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:118) ~[jfxrt.jar:?]
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:40) ~[jfxrt.jar:?]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_121]
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.lambda$handleWindowEvent$423(GlassWindowEventHandler.java:150) ~[jfxrt.jar:?]
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) ~[jfxrt.jar:?]
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:148) ~[jfxrt.jar:?]
at com.sun.glass.ui.Window.handleWindowEvent(Window.java:1266) ~[jfxrt.jar:?]
at com.sun.glass.ui.Window.notifyDestroy(Window.java:1183) ~[jfxrt.jar:?]

编辑 2: Activity 线程列表:

DEBUG [JavaFX Application Thread]        isDeamon : false; name : main
DEBUG [JavaFX Application Thread] isDeamon : true; name : QuantumRenderer-0
DEBUG [JavaFX Application Thread] isDeamon : false; name : JavaFX-Launcher
DEBUG [JavaFX Application Thread] isDeamon : true; name : URL-Loader-2
DEBUG [JavaFX Application Thread] isDeamon : true; name : URL-Loader-1
DEBUG [JavaFX Application Thread] isDeamon : true; name : JavaFX Application Thread
DEBUG [JavaFX Application Thread] isDeamon : true; name : Java2D Queue Flusher
DEBUG [JavaFX Application Thread] isDeamon : true; name : Prism Font Disposer
DEBUG [JavaFX Application Thread] isDeamon : true; name : Reference Handler
DEBUG [JavaFX Application Thread] isDeamon : true; name : Thread-6
DEBUG [JavaFX Application Thread] isDeamon : false; name : AWT-Shutdown
DEBUG [JavaFX Application Thread] isDeamon : true; name : Java2D Disposer
DEBUG [JavaFX Application Thread] isDeamon : true; name : Signal Dispatcher
DEBUG [JavaFX Application Thread] isDeamon : true; name : Disposer
DEBUG [JavaFX Application Thread] isDeamon : true; name : Finalizer
DEBUG [JavaFX Application Thread] isDeamon : false; name : AWT-EventQueue-0
DEBUG [JavaFX Application Thread] isDeamon : true; name : Thread-5
DEBUG [JavaFX Application Thread] isDeamon : true; name : Timer-0

最佳答案

这个问题和OSX System menubar not working in JavaFX具有相同的根本原因,即我正在使用“java -splash:..”的启动屏幕,禁用它可以解决问题。

由于启动屏幕是一个 AWT 功能而不是 JavaFX 功能,因此它似乎是在 AWT 事件线程而不是 JavaFX 事件线程中启动的。

看起来 JavaFX 中的启动画面应该作为 JavaFX Pane 在应用程序内部实现。

关于java - 由于 OSX 中的其他线程,Platform.exit() 未结束 Javafx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41978525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com