zoukankan      html  css  js  c++  java
  • SSH 占用数据库连接不释放问题

    SSH框架的项目在訪问数据库的时候。訪问完毕后一直占用链接,不释放。导致过了一段时间后,server没挂,就是有訪问数据库的连接是时候。一直卡住

    解决的方法:

     

    1.配置spring相应的hibernate文件:

               <prop key="hibernate.connection.release_mode">after_statement</prop> 事务提交后自己主动释放连接

    2配置事务

        

    <!--spring 声明式事务管理器 -->
     <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory" />
     </bean>

     <!--Spring事务拦截器 -->
     <bean id="transactionInterceptor"
      class="org.springframework.transaction.interceptor.TransactionInterceptor">
      <property name="transactionManager" ref="transactionManager" />
      <property name="transactionAttributes">
       <props>
        <!-- 以browse、list、load、get及is开头的全部方法採用仅仅读型事务控制类型 -->
        <prop key="browse*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
        <!-- 全部方法均进行事务控制,假设当前没有事务。则新建一个事务 -->
        <prop key="*">PROPAGATION_REQUIRED</prop>
       </props>
      </property>
     </bean>

     <!-- 自己主动代理类 -->
     <bean
      class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="beanNames">
       <list>
        <value>*Impl</value>
       </list>
      </property>

      <!-- 这个属性为true时。表示被代理的是目标类本身而不是目标类的接口 -->
      <property name="proxyTargetClass">
       <value>true</value>
      </property>

      <!-- 依赖注入上面定义的事务拦截器transactionInterceptor -->
      <property name="interceptorNames">
       <list>
        <value>transactionInterceptor</value>
       </list>
      </property>
     </bean>

     

查看全文
  • 相关阅读:
    在有跳板机的情况下,SecureCRT自动连接到目标服务器
    JavaScript中使用console调试程序的坑
    Python中docstring文档的写法
    Nginx+uWSGI+Django原理
    uWSGI uwsgi_response_write_body_do(): Connection reset by peer 报错的解决方法
    Python LOGGING使用方法
    Python计算斗牛游戏的概率
    Python垃圾回收机制详解
    PhantomJS实现最简单的模拟登录方案
    如何设置Jquery UI Menu 菜单为横向展示
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10664241.html
  • Copyright © 2011-2022 走看看