My Spring起動アプリケーションは、SQLクエリをPostgreSQLデータベースに送信するためにJDBCTemplateを使用します。テンプレートによってプールから接続が確立されるたびに、接続は決して解放されないようです。アクティブな接続の数(datasource.primary.active)は常に増加しています。ログにすべての接続は、SpringのTomcatデータソースプールでアクティブです。
は、SQLクエリはJDBCTemplateを使用した後、私は見ることができます:
DEBUG o.s.j.d.DataSourceUtils - Returning JDBC Connection to DataSource
しかし、同じ値を持つアイドル接続料金の数とアクティブな接続の数が減少していません。最大値に達すると、クエリを実行するために接続を取得することが不可能になります。
だから、データソースプールへの接続が返ってこないと思います。ここで
は、データソース設定がアクチュエータとなっている。
"dataSource": {
"prefix": "spring.datasource.tomcat",
"properties": {
"connectionProperties": null,
"propagateInterruptState": false,
"validator": null,
"useDisposableConnectionFacade": true,
"defaultCatalog": null,
"validationInterval": 3000,
"jmxEnabled": true,
"ignoreExceptionOnPreLoad": false,
"logAbandoned": false,
"commitOnReturn": false,
"password": "******",
"maxIdle": 100,
"testWhileIdle": false,
"removeAbandoned": false,
"poolProperties": {
"dbProperties": {
"user": "postgres",
"password": "******"
},
"url": "jdbc:postgresql://localhost:5432/tvir",
"driverClassName": "org.postgresql.Driver",
"defaultAutoCommit": null,
"defaultReadOnly": null,
"defaultTransactionIsolation": -1,
"defaultCatalog": null,
"connectionProperties": null,
"initialSize": 10,
"maxActive": 100,
"maxIdle": 100,
"minIdle": 10,
"maxWait": 30000,
"validationQuery": "SELECT 1",
"validationQueryTimeout": -1,
"validatorClassName": null,
"validator": null,
"testOnBorrow": true,
"testOnReturn": false,
"testWhileIdle": false,
"timeBetweenEvictionRunsMillis": 5000,
"numTestsPerEvictionRun": 0,
"minEvictableIdleTimeMillis": 60000,
"accessToUnderlyingConnectionAllowed": true,
"removeAbandoned": false,
"removeAbandonedTimeout": 60,
"logAbandoned": false,
"name": "Tomcat Connection Pool[1-574817798]",
"password": "******",
"username": "postgres",
"validationInterval": 3000,
"jmxEnabled": true,
"initSQL": null,
"testOnConnect": false,
"jdbcInterceptors": null,
"fairQueue": true,
"useEquals": true,
"abandonWhenPercentageFull": 0,
"maxAge": 0,
"useLock": false,
"suspectTimeout": 0,
"dataSource": null,
"dataSourceJNDI": null,
"alternateUsernameAllowed": false,
"commitOnReturn": false,
"rollbackOnReturn": false,
"useDisposableConnectionFacade": true,
"logValidationErrors": false,
"propagateInterruptState": false,
"ignoreExceptionOnPreLoad": false,
"useStatementFacade": true
},
とDBを照会するために使用されるコード:
JdbcTemplate jdbcTemplate = appCtx.getBean(JdbcTemplate.class);
ResultSet columns = jdbcTemplate.getDataSource().getConnection().getMetaData().getColumns(null, null, source.getTable().toLowerCase(), null);
String selectList = "";
while (columns.next())
{
String colName = columns.getString("COLUMN_NAME");
String colType = columns.getString("DATA_TYPE");
if(!selectList.equals("")) {
selectList += ", ";
}
if((""+java.sql.Types.INTEGER).equalsIgnoreCase(colType) ||
(""+java.sql.Types.DOUBLE).equalsIgnoreCase(colType) ||
(""+java.sql.Types.BIGINT).equalsIgnoreCase(colType) ||
(""+java.sql.Types.FLOAT).equalsIgnoreCase(colType)) {
selectList += "SUM(" + colName + ")";
} else {
selectList += "MAX(" + colName + ")";
}
selectList += " AS "+colName;
}
String sql = "SELECT "+selectList+" FROM "+source.getTable()+" "+
"WHERE "+source.getDateColumn()+" >= ? "+
"AND "+source.getDateColumn()+" <= ? ";
List<Map<String, Object>> results = jdbcTemplate.queryForList(sql, Date.valueOf(startDate), Date.valueOf(endDate));
これは一般的に間違ったトランザクション設定をしているか、またはバネの範囲外の接続であなたがいじり回っていることを意味します。 -1' 、要求が –
は、ここにデータソースからのparamsですあなたは春の範囲外です。あなたの質問にいくつかのコードと設定を追加してください。 –
が次にあなたが接続をいじりされているjdbcTemplate.queryForList() ''で行われます。 '「defaultTransactionIsolation」:私はデフォルトのトランザクションモードを使用しています –