[英]Schedule a executable file without Windows task scheduler
Is it possible to schedule a executable file to run just before log-off using java? 是否可以安排可执行文件在使用Java注销之前运行? I am working on a application that needed to send a message to the sever just before the system log-off/shutdown.
我正在开发一个需要在系统注销/关机之前向服务器发送消息的应用程序。 But I didn't find any method to solve it.
但是我没有找到任何解决方法。 If anyone know plz help me.
如果有人知道请帮助我。
Thanks in advnce. 提前感谢。
As stated in the comments a ShutdownHook is probably what you are searching for. 如评论中所述,ShutdownHook可能是您要搜索的内容。 Short example:
简短示例:
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
// Code to be executed when JVM exits
System.out.println("JVM exit");
}
});
Note that the ShutdownHook will execute whenever the JVM exits. 请注意,只要JVM退出,ShutdownHook就会执行。 So it will also execute when your program terminates normally.
因此,它将在您的程序正常终止时执行。
If you have any further questions comment on this answer. 如果您还有其他问题,请对此答案发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.