简体   繁体   English

数据库加载批处理作业 Java

[英]Database Loading batch job Java

Have a batch job written in Java which truncates and then loads certain table in Oracle database every few minutes.在 Java 中编写一个批处理作业,它会每隔几分钟截断并加载 Oracle 数据库中的某个表。 There are reports generated on web pages based on the data in the table.根据表中的数据,在 web 页面上生成了报告。 Am wondering of a good way of not affecting the report querying part when the data loading process is happeneing so that the users won't end up with some and/or no data.我想知道在数据加载过程发生时不影响报告查询部分的好方法,这样用户就不会得到一些数据和/或没有数据。

If you process all your SQL statements inside a single transaction there will be always a valid state seen from outside.如果您在单个事务中处理所有 SQL 语句,那么从外部看到的总是有效的 state。 Beware that TRUNCATE doe not work in transactions, so you have to use DELETE .请注意TRUNCATE在事务中不起作用,因此您必须使用DELETE While this guarantees to always have reasonable data in your table it needs a bigger rollback segment and will be considerably slower.虽然这可以保证您的表中始终有合理的数据,但它需要更大的回滚段并且会相当慢。

you could have 2 tables and a meta table which tracks which table is the main table being used for querying.你可以有 2 个表和一个元表,它跟踪哪个表是用于查询的主表。 your batch job will be truncating and loading one of the table and you can switch the main tables once the loading is completed.您的批处理作业将截断并加载其中一个表,加载完成后您可以切换主表。 so the query app will get recent data now and u can load now in the other table所以查询应用程序现在将获取最新数据,您现在可以在另一个表中加载

What I would do is set a flag in a DB table to indicate that that the update is in progress and have the reports look for that flag and display an appropriate message and wait for the update to finish.我要做的是在数据库表中设置一个标志以指示更新正在进行中,并让报告查找该标志并显示适当的消息并等待更新完成。 Once the update is complete clear the flag.更新完成后清除标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM