Java 调用方法jdbcTemplate.getDataSource()时暂停
大家好Java 调用方法jdbcTemplate.getDataSource()时暂停,java,spring,jakarta-ee,Java,Spring,Jakarta Ee,大家好 我有一个应用程序,配置了Spring3和Hibernate3。在应用程序中,所有对数据库的请求都使用JDBCTemplate和HibernateTemplate。在我的例子中,我有一个方法,它注册一个数组参数: protected void registerArrayParameter(PreparedStatement st, int num, Long[] mas) throws SQLException { Connection conn = jdbcTemplate.ge
我有一个应用程序,配置了Spring3和Hibernate3。在应用程序中,所有对数据库的请求都使用JDBCTemplate和HibernateTemplate。在我的例子中,我有一个方法,它注册一个数组参数:
protected void registerArrayParameter(PreparedStatement st, int num, Long[] mas) throws SQLException {
Connection conn = jdbcTemplate.getDataSource().getConnection();
OracleConnection ocon = (OracleConnection) ((DelegatingConnection) conn).getInnermostDelegate();
ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor("CCSYS.NUMBER_TABLE", ocon);
java.sql.Array sqlArray = new oracle.sql.ARRAY(arrayDescriptor, ocon, mas);
st.setArray(num, sqlArray);
}
protected void registerArrayParameter(PreparedStatement st, int num, Long[] mas) throws SQLException {
Connection conn = jdbcTemplate.getDataSource().getConnection();
OracleConnection ocon = (OracleConnection) ((DelegatingConnection) conn).getInnermostDelegate();
ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor("CCSYS.NUMBER_TABLE", ocon);
java.sql.Array sqlArray = new oracle.sql.ARRAY(arrayDescriptor, ocon, mas);
st.setArray(num, sqlArray);
/*added*/
conn.close();
ocon.close();
SomeSource.dataSource.close();
}
经常在jdbcTemplate.getDataSource().getConnection()上挂起(冻结)应用程序。有人知道会是什么吗
感谢您的回复。已解决
在我的例子中,我有一个类扩展了CDATA资源:
public class SomeSource extends BasicDataSource implements Serializable {
public static final long serialVersionUID = 4467486478647684235L;
public static SomeSource dataSource;
public SomeSource(){
super();
/* implementation*/
....
dataSource = this;
}
}
我修改了方法,该方法注册了一个数组参数:
protected void registerArrayParameter(PreparedStatement st, int num, Long[] mas) throws SQLException {
Connection conn = jdbcTemplate.getDataSource().getConnection();
OracleConnection ocon = (OracleConnection) ((DelegatingConnection) conn).getInnermostDelegate();
ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor("CCSYS.NUMBER_TABLE", ocon);
java.sql.Array sqlArray = new oracle.sql.ARRAY(arrayDescriptor, ocon, mas);
st.setArray(num, sqlArray);
}
protected void registerArrayParameter(PreparedStatement st, int num, Long[] mas) throws SQLException {
Connection conn = jdbcTemplate.getDataSource().getConnection();
OracleConnection ocon = (OracleConnection) ((DelegatingConnection) conn).getInnermostDelegate();
ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor("CCSYS.NUMBER_TABLE", ocon);
java.sql.Array sqlArray = new oracle.sql.ARRAY(arrayDescriptor, ocon, mas);
st.setArray(num, sqlArray);
/*added*/
conn.close();
ocon.close();
SomeSource.dataSource.close();
}
之后,应用程序将在不挂起/冻结的情况下工作…不要执行
jdbcTemplate.getDataSource().getConnection()
,因为这会请求springs事务管理之外的连接。它将一直打开直到超时。在某个时刻,您的连接池会耗尽,从而导致应用程序暂停/冻结。您使用的是Java 1.6.0_29吗?isah,我使用的是jdk1.6.0_24M。Deinum,我怎样才能用另一种方式实现这个方法?