Spring和程序化事务管理的连接池问题 [英] Connection pool problem with Spring and programmatic transaction management
问题描述
我需要您的帮助才能解决Spring的连接池问题. 我将Spring与Java 1.4结合使用(无注释).
I need your help in order to solve connection pool problem with Spring. I’m using Spring with Java 1.4 (no annotation).
这是数据源和连接池定义:
Here is the datasource and the connection pool definition:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>${database.jdbcName}</value>
</property>
<property name="url" value="jdbc:sybase:${database.url}">
</property>
<property name="username">
<value>${database.username}</value>
</property>
<property name="password">
<value>${database.password}</value>
</property>
<property name="maxActive">
<value>${database.maxActive}</value>
</property>
<property name="maxIdle" >
<value>${database.maxIdle}</value>
</property>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.connection.release_mode">after_transaction</prop>
<prop key="hibernate.dbcp.maxWait">100000</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
</props>
</property>
...
当所有连接均处于活动状态时,如果系统需要新的连接,我会收到一条消息,提示正在打开JDBC连接",并且所有过程都将停止.我不明白为什么所有线程都被锁定.
When all the connections are active, if the system need a new connection I got a message saying "opening JDBC connection" and all the process are stopped. I don’t understand why all the threads are locked.
所有服务和DAO类在Spring应用程序上下文中均定义为单例.
All services and DAO classes are defined as singletons in Spring application context.
有什么主意吗?
感谢您的帮助.
游侠
推荐答案
您为maxActive
和maxIdle
使用什么值?如果我知道这些值,我可以给您一个更明确的答案,但是与此同时,您也可以尝试将hibernate.dbcp.maxWait
的值从100000
更改为1
,然后再次测试您的应用程序.
What values are you using for maxActive
and maxIdle
? I can give you a more definitive answer if I know those values, but in the meantime you can also try changing the value of hibernate.dbcp.maxWait
from 100000
to 1
and test your application again.
还请确保您没有意外地制作了某些DAO方法synchronized
.
Also make sure you haven't you accidentally made some of your DAO methods synchronized
.
这篇关于Spring和程序化事务管理的连接池问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!