简体   繁体   English

无法在Spring JPA中使用多线程从多个数据库中删除数据

[英]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.

相关问题 多个数据库+具有Spring数据JPA的JNDI进行初始化 - Multiple databases + JNDI with Spring data JPA to initialize Spring JPA 多线程删除争用 - Spring JPA Multithreading delete contention 使用与Spring Boot和Spring Data JPA相同的域模型的多个数据库 - Multiple databases using same domain models with Spring Boot and Spring Data JPA 在spring数据jpa中配置多个具有多个entitymanagerfactory的数据库 - Configuring multiple databases with multiple entitymanagerfactory in spring data jpa 当使用具有 Spring 数据 JPA 的多个数据库时,没有名为“ConfigurationClassPostProcessor.importRegistry”的 bean 出现异常 - When using multiple databases with Spring Data JPA, No bean named “ConfigurationClassPostProcessor.importRegistry” exception occurs 使用Spring,JPA和Hibernate访问Jboss中配置的多个数据库/数据源 - Using Spring, JPA with Hibernate to access multiple databases/datasources configured in Jboss Spring boot JPA如何从同一个连接添加多个数据库? - Spring boot JPA how to add multiple databases from same connection? 使用 Springboot 在 Oracle、MySQL 数据库中创建用户 - Spring Data JPA - Create users in Oracle, MySQL databases using Springboot - Spring Data JPA 无法使用Spring Data JPA创建JOIN - Unable to create a JOIN using Spring Data JPA 如何连接到多个数据库Spring Boot JPA? - How to connect to multiple databases Spring Boot JPA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM