• 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>

     

  • 相关阅读:
    [Bash] Shortcut
    [Bash] Rerun Bash Commands with History Expansions (!! & !$)
    [Bash] Create and Copy Multiple Files with Brace Expansions in Bash
    [Bash] Add Executable Files to $PATH with Bash
    [Typescript] Create Type From Any Given Data in TypeScript
    [Typescript] Ignore Null or Undefined Values with TypeScript Non-Null Assertion Operator
    [Bash] Chain Commands with Pipes and Redirect Output in Bash
    [Bash] Use Conditional Statements in Bash
    [Bash] Understand Exit Statuses in Bash
    监听内容变化 TextWatcher @功能 [MD]
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10664241.html
  • Copyright © 2020-2023  润新知