[英]Unable to delete data from multiple databases using multithreading in spring JPA
I am currently working over database operations to delete data over different database. 我目前正在研究数据库操作,以删除其他数据库上的数据。 I want to run parallel threads in
Spring JPA
to delete data in different databases.I am able to it sequentially. 我想在
Spring JPA
运行并行线程以删除不同数据库中的数据。我能够按顺序进行操作。
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
public void changeAmt() {
//routing db for thread
Query query = (Query)entityManager.createNamedQuery("update_payment_card");
recordCount=query.executeUpdate();
}
I have observed that whenever there is call to this function spring gets the DB
connection using transactionInterceptor
我观察到,只要调用此函数,spring就会使用
transactionInterceptor
获得DB
连接
so every time a thread call this method the underlying db connection changes. 因此,每次线程调用此方法时,基础数据库连接都会更改。
hence only one db get effected. 因此只有一个分贝会生效。
Thanks in advance 提前致谢
Even if you use a connection pool, the connection object reference might differ between successive calls, because the pool will serve you the next available cached connection. 即使使用连接池,连续调用之间的连接对象引用也可能有所不同,因为该池将为您提供下一个可用的缓存连接。
so every time a thread call this method the underlying db connection changes.
因此,每次线程调用此方法时,基础数据库连接都会更改。
hence only one db get effected.
因此只有一个分贝会生效。
You usually have one DataSource configured for one DB schema. 通常,您为一个数据库架构配置了一个数据源。 But multiple concurrent requests may use multiple connections to this data source.
但是,多个并发请求可以使用与此数据源的多个连接。 If you use multiple data bases, you should have multiple Data Sources and you might use JTA to have a global transaction that spans across multiple data sources.
如果使用多个数据库,则应该有多个数据源,并且可能会使用JTA来拥有跨多个数据源的全局事务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.