由于错误配置tomcat + hibernate +数据库而暂停/等待命令进程

时间:2015-03-17 20:29:28

标签: sql-server hibernate tomcat7 c3p0

我正在研究遗留代码,并且我被要求找出sleeping /awaiting command中有这么多sql server db个进程的原因。大多数(如果不是全部)都有program_name = 'jTDS',占用了大量的CPU + physical_io,并且已经超过10天了。

我越来越关注它,我意识到它必须与数据库池有关。

看来我们有2个地方使用数据库池: •context.xml •applicationContext.xml 在应用程序的初始加载时,tomcat读入web.xml,而web.xml又接受context.xml,并创建一个容纳可共享数据库连接的容器。

web.xml还将applicationContext.xml用于弹簧上下文信息。

当sessionFactory需要配置hibernate设置时,它会查找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>

我将maxActive="30" maxIdle="10" maxWait="3000"添加到 context.xml 文件。

我还补充说:

    <prop key="hibernate.c3p0.maxIdleTime">1800</prop>
    <prop key="hibernate.c3p0.idle_test_periods">30</prop>

到applicationContext.xml

看起来有两个地方我们正在设置c3p0值。如果是这种情况,我们是否需要两者?

这是我的问题所在吗? 任何人都可以看到任何错误吗?

0 个答案:

没有答案
相关问题