Java项目开发过程中,有for循环,逐条处理10万条数据。由于逐条处理数据的时候,要更新6~7张表,希望,每次在执行for循环的时候,都对数据库做一次提交。
1.我的处理方法 是,将for循环中的方法提出来,然后,使用spring的手动开启事务的方法,在提取出来的方法上,配置了@Transactional(propagation = Propagation.REQUIRES_NEW),但是测试了几次,都没有效果。
2.由于提出处理的方法中,也有更新表,调用外部系统接口,查询表的操作。所以我想把有关联关系的操作 配置 在一个事务中,然后 外层的事务配置和内层的事务配置 如何来管理?
希望 得到各位的解答,谢谢!!!
高洛峰2017-04-17 17:47:26
If the subject is using spring to do declarative transactions, the method directly calling the internal method will not go to the proxy class (that is, it will not go to the aspect), so @Transactional
may be invalid
Is the external interface here called through the RPC method? If it is called through RPC, it is recommended that the questioner not put it directly into the transaction, because if a timeout occurs, a long transaction will occur, and if the concurrency is large, the database will be damaged When the number of connections is exhausted, the system will become unavailable.
PHP中文网2017-04-17 17:47:26
Place the for loop in the controller layer or non-service layer, and then configure the transaction on the service layer method, so that it should be possible to submit once every time it is called.