SSH Consuming database connection does not release the issue

Source: Internet
Author: User

SSH framework of the project when accessing the database, access after the completion of the link has been occupied, not released, resulting in a period of time after the server is not hanging, is the connection to access the database is the time, has been stuck

Workaround:

1. Configure the hibernate file for spring:

<prop key= "Hibernate.connection.release_mode" >after_statement</prop> automatically release connections after transaction commits

2 Configuring transactions

<!--Spring declarative transaction Manager--
<bean id= "TransactionManager"
class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory"/>
</bean>

<!--spring transaction blocker--
<bean id= "Transactioninterceptor"
class= "Org.springframework.transaction.interceptor.TransactionInterceptor" >
<property name= "TransactionManager" ref= "TransactionManager"/>
<property name= "Transactionattributes" >
<props>
<!--all methods starting with browse, list, load, get, and is read-only transaction control type-
<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>
<!--all methods are transaction controlled, and if there is no transaction, create a new transaction-
<prop key= "*" >PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<!--Auto proxy class--
<bean
class= "Org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" >
<property name= "Beannames" >
<list>
<value>*Impl</value>
</list>
</property>

<!--This property is true, it means that the proxy is the target class itself rather than the target class's interface--
<property name= "Proxytargetclass" >
<value>true</value>
</property>

<!--Dependency injection of the transaction interceptor defined above Transactioninterceptor--
<property name= "Interceptornames" >
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.