C3p0 in hibernate connection Configuration

Source: Internet
Author: User
C3p0 in hibernate connection Configuration

C3p0 Configuration

Hibernate

Connection Pool

Hibernate. Connection. provider_class = net. SF. hibernate. Connection. c3p0connectionprovider

C3p0. minpoolsize = 3

C3p0. maxpoolsize = 15

C3p0. Timeout = 5000 get the connection wait time

C3p0. maxidletime = 1800 connection expiration time

C3p0. max_statements = 100

C3p0. idle_test_period = 3000 every s to test whether the connection can be used normally

C3p0. acquire_increment = 2

C3p0. Validate = true </property> Each connection verifies whether the connection is available.

When you use the c3p0 connection pool settings, you will have the database exception recovery function, but you do not think you will no longer see an exception. An invalid connection in a database session will

Interrupted. For example, if you want to retrieve a connection that has been taken out, or if the connection test is abnormal when they are taken out of the pool, the connection will be interrupted, and you will be throwing

The interrupted connection is displayed in the exception.

Using c3p0 makes it very unlikely to obtain an invalid connection. The most effective way to avoid invalid connections is to set the attribute hibernate. c3p0. Validate to true (in hibernate

So applications that use c3p0 will use the c3p0-native property c3p0. testconnectioncheckout ). Assume that you set the attribute hibernate. c3p0. Validate to true.

, C3p0 tests connections first when obtaining connections. After the database is restarted, your application will never obtain an invalid connection, unless you have obtained a connection when the database is closed.

There is a method to reduce the reliability and prompt the performance, but there is a huge cost, the method is to set c3p0. testconnectionsoncheckin and hibernate. c3p0. idle_test_per

IOD (c3p0-native

C3p0. idleconnectiontestperiod) is a small value. In this solution, all connection tests are asynchronous. You must ensure that when you set idle_test_period

Inter-segment class connections that cannot be tested cannot be taken out. Therefore, if a connection is taken out within a very short period of time, the connection you obtained from the connection pool may not be valid.

Another solution is to set the default connection test in the c3p0 property file to "c3p0. preferredtestquery" or "c3p0. automatictesttable", but it is usually slow.

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.