在一天中的特定时间运行的 Java 程序
有人安排了一个java程序在一天中的特定时间运行吗?平台有什么区别吗?我正在使用Windows。
Have any one scheduled a java program to run at particular time of day? Does platform make any difference? I am using Windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当然,您可以让 Java 程序持续运行,并安排在那里完成的工作。我不知道这是否适合您,但至少您获得了平台独立性。
对于 Java 中的调度,有不同的选项,例如 Quartz、java.util.Timer/java.util.TimerTask等等。我想有很多问题对不同的选择进行评级。
You could of course let the Java program run constantly, and schedule the work to do there. I don't know if that's an option for you, but at least you get platform independence.
For scheduling in Java there's different options like Quartz, java.util.Timer/java.util.TimerTask, etc. I guess there are so questions rating the different alternatives.
对于类 Unix 平台,有 cron。 此 Stackoverflow 问题涵盖了 Windows 上的替代方案。
For unix-like platforms there is cron. This Stackoverflow question covers alternatives on Windows.
您可以使用 Windows 任务计划来安排您的程序。
You can use windows task schedule to schedule your program.
如果您使用的是 Windows,并且有可执行文件,那么使用 Windows Scheduler 怎么样?
编辑
由于您实际上并未使用 Windows:我不知道有什么方法可以安排仍在调试中运行的内容(当然,无论如何编译为可执行文件除外)。
我不熟悉 Unix,但是 看起来您需要在 Unix 上安装某种调度程序(如果尚未安装)并执行相同的操作:本质上调度操作系统来调用可执行文件 - 传递任何必要的参数。
If you're on windows, and you have an executable, how about using the Windows Scheduler?
EDIT
Since you're not actually using windows: I don't know of any way to schedule something that still runs in debug (except, of course, compiling to an executable anyway).
I'm not familiar with Unix, but it looks like you'll need some kind of scheduler on Unix (if one isn't already installed) and do the same thing: essencially schedule the OS to call the executable- passing in whatever arguments are necessary.