简体   繁体   English

使用石英调度程序时,如何处理JavaFX应用程序的应用程序关闭?

[英]How to handle application close for a JavaFX app when using quartz scheduler?

So I want to write a JavaFX app that will have some background tasks using Quartz Scheduler http://www.quartz-scheduler.org/documentation/quartz-2.2.x/quick-start.html#quartz-quick-start-guide 因此,我想编写一个使用Quartz Scheduler进行一些后台任务的JavaFX应用程序http://www.quartz-scheduler.org/documentation/quartz-2.2.x/quick-start.html#quartz-quick-start-guide

Based on their documentation you should call shutdown() at the end. 根据他们的文档,您应该在最后调用shutdown()

How/when/where is the right place to call shutdown() in a JavaFX app so that if the users closes the window or does something that exists the app this function will be called. 在JavaFX应用程序中如何/何时/在何处调用shutdown()的正确位置,这样,如果用户关闭窗口或在应用程序中执行了某些操作,则将调用此函数。

There are 2 places where you could call the shutdown() method. 您可以在2个地方调用shutdown()方法。

First is the stop() method you can override in your Application class. 首先是可以在Application类中重写的stop()方法。 This will be called when your application shuts down. 当您的应用程序关闭时,将调用此方法。 From experiance though, that is not always the case unfortunatly. 从经验来看,不幸的是情况并非总是如此。

So the second one might be a better solution. 因此,第二个可能是更好的解决方案。 Wich is setting the onCloseRequest eventHandler on the stage retrieved from the start() method in your Application class. Wich在从Application类的start()方法检索到的阶段上设置onCloseRequest eventHandler。 Mainly that eventHandler is used to prevent a application from shutingdown (cause of various reasons like unsaved changes etc.), besides it is a failproof way to add a shutdown hook. 主要是使用eventHandler来防止应用程序关闭(由于各种原因,例如未保存的更改等),此外它是添加关闭挂钩的可靠方法。 (like you need) (如您所需要)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM