计划任务问题
我有一个问题:)
假设您获得了一些在未来某个时间点到期的数据。你得到 A 说我的任务在 1 小时内到期,而其他人则说他的任务在 1.5 小时内到期。该信息收集在您的服务器上。用哪种编程语言或者如何解决这个问题?所以任务A将在1h内执行,任务B将在1.5h内执行。我读过一些有关 java 调度程序的内容,但我还不确定这是否是正确的方法。
你的想法是什么?
干杯
I have a though question :)
Let's say you get some data which is due at a certain point int the future. You get A saying my task is due in 1h and other which says his task is due in 1.5h. The information is collected on your server. In which programming language or even how would solve that? So task a will be executed in 1h, task B in 1.5h. I read something about java scheduler but I'm not yet sure if this is the right way.
What are ur ideas?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
cron 安装在大多数 UNIX Web 服务器上 - 您可以使用它来分配稍后执行的任务。
cron is installed on most unix web servers - you can use it to assign tasks to execute later.
如果您正在寻找编程访问,请查看 Quartz - 一个 Java 调度程序。他们还有一个很好的教程资源。
If you are looking for programmatic access then take a look at Quartz - a java scheduler. They also have a good tutorial resource.
如果这是一个长时间运行的进程,那么您可以使用java中的ScheduledExecutorService来实现这一点。显然,如果您的进程退出,那么任务将会丢失。
cron 或quartz 也可以作为更持久的调度程序。但每个人都有自己的皱纹。
If this is a long running process, then you can use a ScheduledExecutorService in java to achieve this. Clearly, though if your process exits, then the task will be lost.
cron or quartz would also work as more persistent schedulers. each has their own wrinkles though.
如果出于某种原因,您决定自己实现这样一个系统,那么这个想法就是这样的。
sleep()
每分钟甚至不规则地唤醒。当守护进程醒来时,它从队列中取出任务;如果任务的到期时间到了,它会在单独的进程(或线程)中运行该任务,并将其从队列中删除。开始所有到期任务后,它会重新进入睡眠状态。If, for some reason, you decide to implement such a system yourself, here's the idea.
sleep()
. When the daemon wake up, it takes tasks from the queue; if task's due time has come, it runs this task in a separate process (or thread), and removes it from the queue. Having started all due tasks, it goes back to sleep.