计划任务问题

发布于 2024-10-12 06:02:55 字数 211 浏览 3 评论 0原文

我有一个问题:)

假设您获得了一些在未来某个时间点到期的数据。你得到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一个人的夜不怕黑 2024-10-19 06:02:55

cron 安装在大多数 UNIX Web 服务器上 - 您可以使用它来分配稍后执行的任务。

cron is installed on most unix web servers - you can use it to assign tasks to execute later.

∞琼窗梦回ˉ 2024-10-19 06:02:55

如果您正在寻找编程访问,请查看 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.

娇妻 2024-10-19 06:02:55

如果这是一个长时间运行的进程,那么您可以使用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.

甜心 2024-10-19 06:02:55

如果出于某种原因,您决定自己实现这样一个系统,那么这个想法就是这样的。

  • 制定一个清单来保存任务,并按截止时间排序。
  • 创建一个大部分时间处于睡眠状态的守护进程,并使用 sleep() 每分钟甚至不规则地唤醒。当守护进程醒来时,它从队列中取出任务;如果任务的到期时间到了,它会在单独的进程(或线程)中运行该任务,并将其从队列中删除。开始所有到期任务后,它会重新进入睡眠状态。
  • 设计一个接口来将新任务添加到队列中。

If, for some reason, you decide to implement such a system yourself, here's the idea.

  • Have a list where you keep your tasks, ordered by due time.
  • Create a daemon process that sleeps most of the time, and wakes e.g. every minute, or even irregularly using 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.
  • Devise an interface to add new tasks to the queue.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文