守护进程无限循环或重复运行
根据oracle调度编写一个“守护进程”哪个更好:
运行一次然后进入无限循环,如果没有什么可做的,就会休眠5秒(为了不浪费CPU周期)。< /p>
启动的那个,检查是否有事情要做。如果不是 - 结束执行并按计划在 5 秒后运行。
您更喜欢哪一个以及为什么?或者可能是另一种实现?
Which is the better to write a "daemon" based on oracle schedules:
The one that is run once and then is in infinite loop and sleeps for 5 seconds if there is nothing to do (to not waste CPU cycles).
The one that is started, checked if it is something to do. If not - ends execution and is run after 5 seconds by schedule.
Which one and why do you prefer? Or may be it is some another implementation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人更喜欢无限循环而不是计划任务。通过无限循环,您可以看到更广泛的交叉激活概述 - 例如,您可以非常轻松地计算连续/类似的故障数量并添加错误恢复。
计划任务实际上是无状态的,除非您手动赋予它状态(文件/数据库/???)
I personally prefer an infinite loop to a scheduled task. With an infinite loop you can see a broader cross-activation overview - Eg You can count number of failures in a row/similar very easily and add error-recovery.
A scheduled task is effectively stateless unless you manually give it state (File/Db/???)
听起来您可能想考虑使用队列来进行处理而不是调度作业。该进程可能会阻塞在队列中等待新的工作。
It sounds like you might want to look at using an a queue to do the processing rather than a schedule job. The process can block on the queue waiting for new work.