【发布时间】:2019-03-06 10:56:32
【问题描述】:
我使用的是Oracle UCP JDBC,下面的方法是从连接池中获取连接。
private static PoolDataSource poolDataSource;
....
static synchronized Connection createConnection() throws SQLException {
if (poolDataSource == null) {
poolDataSource = PoolDataSourceFactory.getPoolDataSource();
poolDataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
poolDataSource.setURL(url);
poolDataSource.setUser(user);
poolDataSource.setPassword(password);
poolDataSource.setInitialPoolSize(1);
poolDataSource.setMinPoolSize(1);
poolDataSource.setMaxPoolSize(10);
}
Connection connection = poolDataSource.getConnection();
return connection;
}
我知道有 Connection.isValid() 方法来检查从池中获得的连接是否有效。但是如果 isValid() 返回 false,我该怎么办?如何强制连接池重新建立连接?
另外,请注意,在我们的测试环境中,我们没有使用 RAC(Real Application Clusters),但在生产环境中,我们确实有 RAC。我已经阅读了关于 RAC 的内容,我们需要在代码中进行一些配置才能使 RAC 工作。
是否可以为 RAC 和非 RAC 环境使用相同的代码,以便重新建立池中的无效连接?
提前致谢。
【问题讨论】:
标签: oracle jdbc connection-pooling ucp