简体   繁体   English

在没有Windows任务计划程序的情况下计划可执行文件

[英]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.

相关问题 在没有Windows Task Scheduler的情况下安排任务 - Scheduling tasks without windows task scheduler 使用 Windows 任务计划程序打开 Excel 文件 - Open Excel file using Windows Task Scheduler 使用Windows任务计划程序自动执行WAR文件 - Using Windows Task Scheduler to automate execution of WAR file 在Java中的Windows Task Scheduler中注册任务 - Register task in windows task scheduler in java 如何使用日历对象在Spring Scheduler中计划任务? - how to schedule task in spring scheduler by using calendar object? 如何在运行时调度任务,其中调度程序的频率从数据库中读取 - How to schedule a task at runtime where the frequency of the scheduler is read from the database Java 8 - Quartz Scheduler 每天在特定时间安排任务 - Java 8 - Quartz Scheduler to schedule task for specific time daily 为什么不能使用计划程序计划固定延迟任务 - Why can't I schedule a fixed delay task using scheduler 使用Windows Scheduler计划任务以运行.jar文件以及.ini配置文件 - Scheduling task with windows scheduler to run .jar file along with .ini configuration file 如何在Windows中使用Task Scheduler运行JavaApp? - How to Run JavaApp with Task Scheduler in windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM