在我正在进行的项目中,我们需要在jetty停止之前“保存”工作,在Linux上这很容易,因为我们可以调用另一个进程,在Windows上,这并不容易,因为我们正在注册到Windows服务,这意味着我们可以修改start.jar文件以在调用“stop”函数之前进行一些操作,或者,在这里我需要帮助:
我想,jetty在触发stop()函数之前,甚至在调用start.Main类之前执行一些进程,这可能吗?
谢谢
最佳答案
使用shutdown hooks :
When the virtual machine begins its shutdown sequence it will start all registered shutdown hooks in some unspecified order and let them run concurrently. When all the hooks have finished it will then run all uninvoked finalizers if finalization-on-exit has been enabled. Finally, the virtual machine will halt.
也就是说,关闭钩子(Hook)使 JVM 保持运行,直到钩子(Hook)终止(从 run() 方法返回。
您必须使用此功能扩展 Jetty 代码。
关于java - 在 jetty 停止之前调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21183302/