2014-01-08 70 views
0

大家好!
我有一个应用程序,它使用spring 3和hibernate 3进行配置。应用程序使用JDBCTemplate和HibernateTemplate对数据库进行的所有请求。在我的情况下,我有一种方法,其记录一个数组参数:上jdbcTemplate.getDataSource暂停调用方法jdbcTemplate.getDataSource()

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); 
} 

通常应用暂停(冻结)()的getConnection()。
有人可以知道它是什么吗?
感谢您的回复。

+2

不要执行'jdbcTemplate.getDataSource()。getConnection()',因为这会请求在事务管理之外的连接。在它超时之前它将保持打开状态。在某些时候,您的连接池将耗尽,导致应用程序暂停/冻结。 –

+0

你使用Java 1.6.0_29吗? – isah

+0

isah,我正在使用jdk1.6.0_24 – bito4ek

回答

0

解决!
在我的情况我有一个类继承BasicDataSourse:

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); 

    /*added*/ 
    conn.close(); 
    ocon.close(); 
    SomeSource.dataSource.close(); 
} 

该应用钢加工而不暂停/冷冻后...