Java调度与SQL调度
这是我的要求:
将日期与每条记录一起插入到数据库表中。两周 在该具体日期之前,应将单独的记录输入到 不同的表。
我最初的解决方案是建立一个 SQL 调度作业,但我的客户坚持要求通过 java 处理它。
- 对此最好的方法是什么?
- 对于此任务使用 SQL 调度作业和 Java 调度有何优缺点?
Here is my requirement:
a date is inserted in to a db table with each record. Two weeks
before that particulate date, a separate record should be entered to a
different table.
My initial solution was to put up a SQL schedule job, but my client insisted on it being handled through java.
- What is the best approach for this?
- What are the pros and cons of using SQL schedule job and Java scheduling for this task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问自己一个问题:这件作品属于哪个领域?如果数据完整性需要它,那么显然是 DBMS 的问题,最好在那里处理。如果它是业务领域而不是数据的一部分,或者可能需要 DBMS 不可用或不自然的信息或处理,那么最好将其放在外部。
我想说,使用最适合工作的工具。让数据库使用它提供的任何功能来处理内容通常是很好的。例如,我通常喜欢在另一个表中保留记录状态更新“快照”的日志表有一个触发器,从而将这一责任从我的应用程序手中夺走。
但这几乎在任何 DBMS 中都可用。其他数据库可能无法提供您所需的作业调度功能。如果可以想象有一天您将切换到不同的 DBMS,那么无论如何您都将被迫使用 Java 进行操作。这就是 Java 方法的优点:您可以获得独立于数据库的功能。如果您将纯 JDBC 与标准 SQL 查询结合使用,那么您就获得了完全可移植的解决方案。
这两种方法似乎都有效。考虑一下什么会引起最少的工作和担忧。如果它是用 Java 完成的,您需要确保该进程正在运行或已计划。这是一些外部依赖。如果它在数据库中,那么只要数据库启动,您就可以确保工作已完成。
Ask yourself the question: to what domain does this piece of work belong? If it's required for data integrity, then it's obviously the DBMS' problem and would probably best be handled there. If it's part of the business domain rather than the data, or might require information or processing that's not available or natural to the DBMS, it's probably best made external.
I'd say, use the best tool for the job. Having stuff handled by the database using whatever features it offers is often nice. For example, a log table that keeps "snapshots" of status updates of records in another table is something I typically like to have a trigger for, taking that responsibility out of my app's hands.
But that's something that's available in practically any DBMS. There's the possibility that other databases won't offer the job scheduling capacities you require. If it's conceivable that some day you'll be switching to a different DBMS, you'll then be forced to do it in Java anyway. That's the advantage of the Java approach: you've got the functionality independently of the database. If you're using pure JDBC with standard SQL queries, you've got a fully portable solution.
Both approaches seem valid. Consider what induces the least work and worries. If it's done in Java you'll need to make sure that process is running or scheduled. That's some external dependency. If it's in the database, you'll be sure the job is done as long as the DB is up.
好吧,首先,如果你想用 Java 来做,你可以使用 计时器用于简单的基本重复性工作,或Quartz 了解更高级的内容。
我个人还认为,让同一个实体(应用程序)处理所有相关的数据库操作会更好。换句话说,如果您的 Java 应用程序正在从数据库读取/写入,则它应该保持一致,并且还处理计划的读取/写入。而且作为一个优点,通过这种方式,您可以更轻松地同步您的操作,例如,如果您想确保计划的作业正在运行、已开始、已完成,那么如果所有操作都在 Java 中完成,那么您可以更轻松地做到这一点使用不同的进程(如 SQL 调度程序)来执行此操作。
Well, first off, if you want to do it in Java, you can use the Timer for a simple basic repetitive job, or Quartz for more advanced stuff.
Personally I also think that it would be better to have the same entity (application) deal with all related database actions. In other words, if your Java app is reading/writing to/from the db, it should be consistent and also deal with scheduled reading/writings. And as a plus, this way you can synchronize your actions easier, like, if you want to make sure that a scheduled job is running, has started, has finished, you can do that a lot easier if all is done in Java as compared with having a different process (like the SQL Scheduler) doing it.