如何处理Java中的关闭应用程序事件? [英] How to handle a closing application event in Java?
本文介绍了如何处理Java中的关闭应用程序事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何解决方案?谢谢!
解决方案
您想使用关机挂钩:
调用Runtime.getRuntime()addShutdownHook(theHookThread)。
所以线程将在JVM关闭时运行,请参阅这里的详细信息。 p>
Having a console application, a server accepting several connections from clients, is it possible to have a listener or an event on a closing application? I want, in this event, tell all connected clients to gently disconnect before the application really closes itself.
Any solution? Thank you!
解决方案
You want to use a shutdown hook:
Runtime.getRuntime().addShutdownHook(theHookThread);
So the thread will be run when the JVM shuts down, see here for details.
这篇关于如何处理Java中的关闭应用程序事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文