C3P0 Hibernate database Connection release policy

Source: Internet
Author: User
Tags connection pooling

Policies for connection deallocation in Hibernate Hibernate.connection.release_mode There are four properties:

Defaults: Default mode
The connection is released when the On_close:session is closed.

After_transcation: The release of a connection as a transaction at the end of transaction processing

After_statement: Releases the current connection after each execution.

The granularity of the four release connections, from coarse to fine:

with the first default configuration, the transaction management is configured in spring, because the transaction granularity is small, the transaction execution ends, and the released operation is not triggered until the maximum time-out for the connection setting is reached to reclaim the connection and the connection is delayed, causing The connection pool is fully occupied.

The second type of on_close, which also configures transactions in spring, will not be released until the session is closed, releasing slower, and also causing the connection pool to be stained

Use the After_transcation policy to release the link, and each transaction will release the link. With the configuration of the XML configuration for global transaction management, there is no connection pooling. However, if an annotation is used, and the DAO class of a persistence layer does not annotate transactional annotations, or if a DAO's transaction management configuration is omitted from the XML configuration, then the DAO operation ends, not the end of a transaction, the link is not released, and the link is delayed. The connection pool is fully occupied over time.

After_statement the policy release connection in time. However, there is also a disadvantage, because each execution will release the connection, if a transaction requires a few operations, but the first execution of the connection is released, the connection has been returned to the connection pool, the second execution to obtain a new connection, so that there is no guarantee of transactional.

C3P0 Hibernate database Connection release policy

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.