Database connections occupied by SSH are not released

Source: Internet
Author: User

When a project in the SSH framework accesses the database, the link is always occupied and not released after the access is completed. As a result, after a period of time, the server does not fail, that is, the connection to the database is required, always stuck

Solution:

 

1. Configure the hibernate file corresponding to spring:

<Prop key = "hibernate. connection. release_mode"> after_statement </prop> the connection is automatically released after the transaction is committed.

2. Configure transactions

<! -- Spring declarative Transaction Manager -->
<Bean id = "transactionManager"
Class = "org. springframework. orm. hibernate3.HibernateTransactionManager">
<Property name = "sessionFactory" ref = "sessionFactory"/>
</Bean>

<! -- Spring transaction interceptor -->
<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 use read-only transaction control types -->
<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 subject to transaction control. If no transaction exists, a new transaction is created. -->
<Prop key = "*"> PROPAGATION_REQUIRED </prop>
</Props>
</Property>
</Bean>

<! -- Automatic proxy -->
<Bean
Class = "org. springframework. aop. framework. autoproxy. BeanNameAutoProxyCreator">
<Property name = "beanNames">
<List>
<Value> * Impl </value>
</List>
</Property>

<! -- If this attribute is true, it indicates that the proxy is the interface of the target class rather than the target class. -->
<Property name = "proxyTargetClass">
<Value> true </value>
</Property>

<! -- Dependency injection the transaction interceptor transactionInterceptor defined above -->
<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.