Hi Spring guys:
A Sun's engineer in our company told us that the code in finally block may not be executed immediately in high volume conditions. The test engineers in our company told us that they found that the connection may not be released immdiately too when the connection is closed in finally block (The code is our a utility class that may act as the same as spring's JdbcTemplate). I can not believe this, so i checked you guys' code "JdbcTemplate". I found that you guys do the same thing as me: to release resouce in finally block
Code:public Object execute(final StatementCallback action) { Connection con = DataSourceUtils.getConnection(getDataSource()); Statement stmt = null; try { Connection conToUse = con; if (this.nativeJdbcExtractor != null && this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativeStatements()) { conToUse = this.nativeJdbcExtractor.getNativeConnection(con); } stmt = conToUse.createStatement(); DataSourceUtils.applyTransactionTimeout(stmt, getDataSource()); Statement stmtToUse = stmt; if (this.nativeJdbcExtractor != null) { stmtToUse = this.nativeJdbcExtractor.getNativeStatement(stmt); } Object result = action.doInStatement(stmtToUse); SQLWarning warning = stmt.getWarnings(); throwExceptionOnWarningIfNotIgnoringWarnings(warning); return result; } catch (SQLException ex) { throw getExceptionTranslator().translate("executing StatementCallback", null, ex); } finally { JdbcUtils.closeStatement(stmt); DataSourceUtils.closeConnectionIfNecessary(con, getDataSource()); } }
Can you guys give me some test results about this. And did you guys come with the same problems like our test engineer? Thanks.
Regards
Eisen


Reply With Quote