问题
I am working on a legacy code and I was asked to find out why there are so many sleeping /awaiting command
processes in sql server db
. Most if not all of them have a program_name = 'jTDS'
, take up a lot of CPU + physical_io and are 10+ days old.
More I was looking into it more I was realizing that it must have something to do with database pooling.
It appears as we have 2 places where we are using db pooling: • context.xml • applicationContext.xml On initial load of application, tomcat reads in web.xml which in turn takes context.xml and it creates a container holding shareable db connection.
web.xml also takes applicationContext.xml for spring context information.
When sessionFactory needs to configure hibernate setting it looks for hibernateProperties.
context.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>
applicationContext.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 context.xml file.
I also added:
<prop key="hibernate.c3p0.maxIdleTime">1800</prop>
<prop key="hibernate.c3p0.idle_test_periods">30</prop>
to applicationContext.xml
It looks like there are 2 places where we are setting c3p0 values. If this is the case do we need both?
Is this where my problem is? Can anyone see anything wrong?
来源:https://stackoverflow.com/questions/29109082/sleeping-awaiting-command-processes-due-to-misconfiguring-tomcathibernatedatab