使用SimpleJDBCall时如何在spring中关闭refcursor
我正在使用spring SimpleJDBCall调用oracle存储过程,我正在使用oracle 11g 我无意中发现了一些帖子,它们表明可能存在内存泄漏,因为ref游标在spring之前没有正确关闭 在使用spring SimpleJDBCall时,是否仍然可以显式关闭游标?还是增加oracle OPEN_光标是唯一的出路使用SimpleJDBCall时如何在spring中关闭refcursor,spring,oracle,jdbc,Spring,Oracle,Jdbc,我正在使用spring SimpleJDBCall调用oracle存储过程,我正在使用oracle 11g 我无意中发现了一些帖子,它们表明可能存在内存泄漏,因为ref游标在spring之前没有正确关闭 在使用spring SimpleJDBCall时,是否仍然可以显式关闭游标?还是增加oracle OPEN_光标是唯一的出路 我计划将我的应用程序扩展到每小时处理大约一百万个事务。任何建议都会很有帮助。实际上Spring JDBC没有这样的问题。执行后,它最终关闭中的所有资源SimpleJDBC
我计划将我的应用程序扩展到每小时处理大约一百万个事务。任何建议都会很有帮助。实际上Spring JDBC没有这样的问题。执行后,它最终关闭
中的所有资源SimpleJDBCall
使用JdbcTemplate
:
public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
throws DataAccessException {
try {
...
}
catch (SQLException ex) {
...
}
finally {
if (csc instanceof ParameterDisposer) {
((ParameterDisposer) csc).cleanupParameters();
}
JdbcUtils.closeStatement(cs);
DataSourceUtils.releaseConnection(con, getDataSource());
}
}
从另一方面来说,我对SpringJDBC和Oracle在高负载系统中的应用有着丰富的经验,我想说的是,我们注意到Oracle上有足够多的开放资源处于峰值负载,但在这之后,它们已经得到了适当的释放
虽然我们使用了JBOSS Poolled数据源及其事务管理器
但我直接使用CallableStatement,我可以快速安全地释放语句和连接,尝试这两种方法并测量内存消耗,它完美地解决了内存消耗和连接保留问题,这证明了应用程序中存在许多等待和拒绝连接的情况
try {
log.info("**** RepositoryPSostgres.getAllProducts ******** ");
Connection conn = jdbcTemplate.getDataSource().getConnection();
conn.setAutoCommit(false);
// Procedure call.
CallableStatement proc = conn.prepareCall("{? = call get_all_products() }");
proc.registerOutParameter(1, Types.OTHER);
proc.execute();
ResultSet results = (ResultSet) proc.getObject(1);
**proc.close();
proc.isClosed();
conn.close();**
ArrayList <Products> resp = new ArrayList <Products>();
while (results.next()) {
Products resp1 = new Products();
resp1.setId(results.getInt("id"));
resp1.setName((String) results.getString("name"));
resp1.setPrice((BigDecimal) results.getBigDecimal("price"));
resp.add(resp1);
log.info("***" + results.getInt("id") + "***** ");
log.info("***" + results.getString("name") + "***** ");
log.info("***" + results.getBigDecimal("price") + "***** ");
}
results.close();
return resp;
} catch (Exception e) {
e.printStackTrace();
log.error(new StringBuffer("Error en transaccion en saldo CashPooling : ").append(e.getLocalizedMessage()).toString());
return null;
}
试试看{
log.info(“*****RepositoryPSostgres.getAllProducts********”);
连接连接=jdbcTemplate.getDataSource().getConnection();
连接设置自动提交(错误);
//过程调用。
CallableStatement proc=conn.prepareCall(“{?=call get_all_products()}”);
proc.registerOutParameter(1,type.OTHER);
proc.execute();
ResultSet results=(ResultSet)proc.getObject(1);
**过程关闭();
进程isClosed();
康涅狄格州关闭()**
ArrayList resp=新的ArrayList();
while(results.next()){
Products resp1=新产品();
resp1.setId(results.getInt(“id”));
resp1.setName((String)results.getString(“name”);
resp1.setPrice((BigDecimal)results.getBigDecimal(“price”);
分别增加(第1项);
log.info(“***”+results.getInt(“id”)+“****”);
log.info(“***”+results.getString(“name”)+“****”);
log.info(“***”+results.getBigDecimal(“价格”)+“****”);
}
结果:关闭();
返回响应;
}捕获(例外e){
e、 printStackTrace();
log.error(新的StringBuffer(“transaccion en saldo现金池错误:”).append(例如getLocalizedMessage()).toString());
返回null;
}
谢谢你,阿泰姆。这很有帮助!!
try {
log.info("**** RepositoryPSostgres.getAllProducts ******** ");
Connection conn = jdbcTemplate.getDataSource().getConnection();
conn.setAutoCommit(false);
// Procedure call.
CallableStatement proc = conn.prepareCall("{? = call get_all_products() }");
proc.registerOutParameter(1, Types.OTHER);
proc.execute();
ResultSet results = (ResultSet) proc.getObject(1);
**proc.close();
proc.isClosed();
conn.close();**
ArrayList <Products> resp = new ArrayList <Products>();
while (results.next()) {
Products resp1 = new Products();
resp1.setId(results.getInt("id"));
resp1.setName((String) results.getString("name"));
resp1.setPrice((BigDecimal) results.getBigDecimal("price"));
resp.add(resp1);
log.info("***" + results.getInt("id") + "***** ");
log.info("***" + results.getString("name") + "***** ");
log.info("***" + results.getBigDecimal("price") + "***** ");
}
results.close();
return resp;
} catch (Exception e) {
e.printStackTrace();
log.error(new StringBuffer("Error en transaccion en saldo CashPooling : ").append(e.getLocalizedMessage()).toString());
return null;
}