java spring DriverManagerDataSource 打开了很多连接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11500804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
spring DriverManagerDataSource opens up many connections?
提问by user1016403
I am using spring and hibernate stand-alone applications. I am using below configuration.
我正在使用 spring 和 hibernate 独立应用程序。我正在使用以下配置。
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.some.SomePojo</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${mdm.db.dialect}</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Is DriverManagerDataSource opens up a database connection every time data is requested? or does it reuses already opened connection? Also, does it close idle connections? to make use of the connection pooling concept do I need c3p0?
每次请求数据时,DriverManagerDataSource 是否都会打开数据库连接?还是重用已经打开的连接?另外,它会关闭空闲连接吗?要利用连接池概念,我需要 c3p0 吗?
Thanks!
谢谢!
回答by Mark Bakker
The java doc states;
Java 文档指出;
This class is not an actual connection pool; it does not actually pool Connections.
此类不是实际的连接池;它实际上并不池连接。
See for more info
查看更多信息