gpt4 book ai didi

java - Atomikos、Java 8 和多个数据库

转载 作者:太空宇宙 更新时间:2023-11-04 12:24:31 28 4
gpt4 key购买 nike

我们有一个应用程序在 Java 7 上运行良好几年,但在升级到 Java 8 时遇到问题。数据库连接似乎是问题所在。

情况是这样的:该应用程序访问 200 多个数据库。或者,从技术上讲,一个数据库安装有 200 个不同的模式。我们使用 Atomikos 作为数据源。当使用 Java 7 启动应用程序时,可能会对数据源进行一些顺序迭代,因为我们已将最大池大小设置为 5。这需要一点时间,但实际上没有问题。

当我们尝试使用 Java 8 运行时,我的猜测是它会尝试并行执行所有操作。应用程序在启动时崩溃,如下所示:

05:21:39.611 INFO [main] o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'database.np' 05:21:41.389 INFO [main] o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'database.np_000000000_0000' 05:21:41.796 INFO [main] o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'database.np_000000001_0000' 05:22:11.890 WARN [main] c.atomikos.jdbc.AtomikosSQLException - Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean. 05:22:41.991 WARN [main] c.atomikos.jdbc.AtomikosSQLException - Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean. 05:22:41.998 ERROR [main] o.h.tool.hbm2ddl.SchemaValidator - HHH000319: Could not get database metadata com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean. at com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:46) ~[transactions-jdbc-3.9.3.jar:na] at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:90) ~[transactions-jdbc-3.9.3.jar:na] at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:85) ~[transactions-jdbc-3.9.3.jar:na]

So, we try the advice in the stacktrace, and increase maxPoolSize to a suitable number above 200. Then we can actually start the application, but... It seems like a complete overkill, and to make matters worse, the application doesn't like having so many connections it doesn't really use - the databases/schemas are accessed only now and then. We see the following in the log:

11:08:26.970 [Atomikos:0] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceNp': connection idle for 358671ms 11:08:26.970 [Atomikos:0] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceNp': connection idle for 357953ms 11:08:26.970 [Atomikos:0] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceNp': connection idle for 357947ms 11:08:26.970 [Atomikos:0] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceNp': connection idle for 26425ms 11:08:26.970 [Atomikos:0] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceNp': current size: 1/4 11:08:29.983 [Atomikos:1] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceRolp': trying to shrink pool 11:08:29.984 [Atomikos:1] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceRolp': connection idle for 359790ms | (repeat 200 times...) | atomikos connection pool 'dataSourceRolp': connection idle for 263450ms 11:07:29.983 [Atomikos:1] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceRolp': connection idle for 263446ms 11:07:29.983 [Atomikos:1] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceRolp': connection idle for 263168ms 11:07:29.983 [Atomikos:1] DEBUG c.a.datasource.pool.ConnectionPool - atomikos connection pool 'dataSourceRolp': current size: 1/208

有什么想法吗?出于法律原因,我们需要将 200 多个模式分开。除此之外,我们可以相当自由地选择我们想要的技术解决方案。

最佳答案

您使用什么数据库?我在数据库迁移期间(从 Oracle 到 PostgreSQL)遇到了非常类似的问题。

我们将数据源定义为 JNDI,并且为了创建数据源,我们还从 jdbc 拦截器中删除了一些属性。

如果您使用 PostgreSQL,请检查您为数据源定义的 Bean 类型。

关于java - Atomikos、Java 8 和多个数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38514291/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com