我正在研究遗留代码,有人要求我找出为什么有这么多sleeping /awaiting command
进程在sql server db
。大多数(如果不是全部)都有program_name = 'jTDS'
,占用大量 CPU +physical_io,并且已存在 10 天以上。
我越深入地研究它,我意识到它一定与数据库池有关。
看来我们有两个地方正在使用数据库池:
• 上下文.xml
• applicationContext.xml
在初始加载应用程序时,tomcat 会读取 web.xml,而 web.xml 又会获取 context.xml,并创建一个保存可共享数据库连接的容器。
web.xml 还采用 applicationContext.xml 作为 spring 上下文信息。
当 sessionFactory 需要配置 hibernate 设置时,它会查找 hibernateProperties。
上下文.xml
<Resource auth="Container" description="DAPS Database"
driverClass="net.sourceforge.jtds.jdbc.Driver"
name="jdbc/vda" user="****" password="*****"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:jtds:sqlserver://localhost/dbname;user=sa;password=****;TDS=8.0" />
web.xml
<resource-ref>
<description>Pooled Database Resource</description>
<res-ref-name>jdbc/vda</res-ref-name>
<res-type>ja`vax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
应用程序上下文.xml
<!-- Data Source using C3P0 database connection pooling -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/vda</value>
</property>
</bean>
<!-- Hibernate properties to be used in the Session Factory -->
<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.c3p0.min_size">4</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
<prop key="hibernate.c3p0.max_statements">20</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties" ref="hibernateProperties" />
<property name="mappingResources">
<list>
<value>model/businessobject/login/User.hbm.xml</value>
</list>
</property>
</bean>
I added maxActive="30" maxIdle="10" maxWait="3000"
to 上下文.xml file.
我还补充道:
<prop key="hibernate.c3p0.maxIdleTime">1800</prop>
<prop key="hibernate.c3p0.idle_test_periods">30</prop>
到 applicationContext.xml
看起来我们在两个地方设置 c3p0 值。如果是这种情况,我们两者都需要吗?
这是我的问题所在吗?
谁能看出有什么问题吗?