安排java程序
我想定期运行我的java程序,比如说每3小时一次。我正在考虑编写一个 .bat 文件并放置命令来调用 java 类。但是在 Windows XP 中定期运行 .bat 的最佳方法是什么?提前致谢。我不想使用第三方工具。
I want to run my java program in regular interval , lets say, in every 3 hours. I am thinking to write a .bat file and put command to call java class. But what is the best way to run .bat regularly in windows xp. Thanks in advance. I dont want to use third party tool.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Windows 计划任务正是为此目的而构建的。
您可以按多个计划运行事物(这样您就可以获得每三个小时的行为),并且无论是否登录都可以运行代码。
多个计划有点棘手。您基本上将其设置为日常任务,但在接近结束时,它会询问您是否想要执行高级功能。
选择是,然后您可以在此时设置多个计划。
Windows scheduled tasks are built for exactly that purpose.
You can run things on multiple schedules (so you can get your every-three-hour behaviour) and you can get your code to run whether or not logged in.
The multiple scheduling is a bit tricky. You basically set it up as a daily task to start with but, near the end, it will ask you if you want to do advanced features.
Select yes then you can set up multiple schedules at that point.
如果您想要一个纯粹的基于 Java 的解决方案,您可以尝试 QUARTZ SCHEDULER。但正如 paxdiablo 已经提到的,Windows 任务计划程序也会这样做。
If you want a pure Java Based solution you can try QUARTZ SCHEDULER. But as paxdiablo already mentioned, Windows Task Scheduler will do that as well.