Comparison of several connection pools in spring

Source: Internet
Author: User
Tags connection reset
Comparison of several connection pools in spring
Hibernate
C3p0 is recommended for the development team, and DBCP is recommended for the spring development team. However, the DBCP connection pool has the same issue as the Weblogic connection pool, that is, after the connection is forcibly closed or the database is restarted, no
Method <! -- Startfragment --> reconnect indicates that the connection is reset. This setting can be fixed. Hibernate in
C3p0 and proxool are recommended for action.

I recommend proxool because it not only monitors the background. You can also release connections effectively. In connection close, that is, return the connection,
Close all statement and determine whether it is autocommit. If not, roll back and set true,
Refer to the org. logicalcobwebs. proxool. connectionresetter class of proxool.
The connection pool sets the Connection reset back to the initial state.
DBCP Configuration
<Bean id = "datasource" class = "org. Apache. commons. DBCP. basicdatasource" Destroy-method = "close">
<Property name = "driverclassname" value = "$ {dB. driverclassname}"/>
<Property name = "url" value = "$ {dB. url}"/>
<Property name = "username" value = "$ {dB. Username}"/>
<Property name = "password" value = "$ {dB. Password}"/>

<Property name = "validationquery">
<Value> select 1 </value>
</Property>
<Property name = "testonborrow">
<Value> true </value>
</Property>

</Bean>

C3p0 configuration, <! -- Startfragment --> Note: ''driverclass', 'jdbcurl', 'user', 'Password'

<Bean id = "datasource" class = "com. mchange. v2.c3p0. combopooleddatasource" Destroy-method = "close">
<Property name = "driverclass">
<Value> net. SourceForge. jtds. JDBC. Driver </value>
</Property>
<Property name = "jdbcurl">

<Value> JDBC: jtds: sqlserver: // localhost: 1433/Hua </value>
</Property>
<Property name = "user">
<Value> SA </value>
</Property>
<Property name = "password">
<Value> Hua </value>
</Property>
<Property name = "minpoolsize">
<Value> 15 </value>
</Property>
<Property name = "acquireincrement">
<Value> 5 </value>
</Property>
<Property name = "maxpoolsize">
<Value> 25 </value>
</Property>
</Bean>

Or

<Bean id = "c3p0datasource" class = "com. mchange. v2.c3p0. combopooleddatasource"
Destroy-method = "close">
<Property name = "driverclass">
<Value >$ {dB. driverclass} </value>
</Property>
<Property name = "jdbcurl">
<Value >$ {dB. url} </value>
</Property>
<! --
<Property name = "user">
<Value >$ {dB. User} </value>
</Property>
<Property name = "password">
<Value >$ {dB. Pass} </value>
</Property>
-->
<Property name = "properties">
<Props>
<Prop key = "c3p0. acquire_increment"> 5 </prop>
<Prop key = "c3p0. idle_test_period"> 100 </prop>
<Prop key = "c3p0. Max _size"> 100 </prop>
<Prop key = "c3p0. max_statements"> 0 </prop>
<Prop key = "c3p0. min_size"> 10 </prop>
<Prop key = "user" >$ {dB. User} </prop>
<Prop key = "password" >$ {dB. Pass} </prop>
</Props>
</Property>
</Bean>
Xapool Configuration
<Bean id = "datasource" class = "org. enhydra. JDBC. Pool. standardpooldatasource" Destroy-method = "stoppool">
<Constructor-Arg Index = "0">
<Bean class = "org. enhydra. JDBC. Standard. standardconnectionpooldatasource">
<Property name = "drivername"> <value> com. MySQL. JDBC. Driver </value> </property>
<Property name = "url"> <value> JDBC: mysql: // localhost/dbname </value> </property>
</Bean>
</Constructor-Arg>
<Property name = "user"> <value> root </value> </property>
<Property name = "password"> <value> mypass </value> </property>
<Property name = "minsize"> <value> 1 </value> </property>
<Property name = "maxsize"> <value> 5 </value> </property>
<Property name = "jdbcteststmt"> <value> select 1 </value> </property>
</Bean>
C-jdbc Configuration
<Bean id = "datasource" class = "org. objectweb. cjdbc. Driver. datasource">
<Property name = "url"> <value> JDBC: cjdbc: // 127.0.0.1: 25322/vdb? User = vuser </value> </property>
</Bean>

WebLogic connection pool solution: Test reserved connections: If this option is selected, the server will provide the connection to the client before
Test it. Test created connections: If this option is selected, a JDBC
Test the JDBC connection after the connection and before adding it to the list of available connections in the JDBC connection pool.

The configuration of DBCP in Tomcat's JNDI:

<Parameter>
<Name> factory </Name>
<Value> org. Apache. commons. DBCP. basicperformancefactory </value>
</Parameter>
<Parameter>
<Name> driverclassname </Name>
<Value> com. Sybase. jdbc2.jdbc. sybdriver </value>
</Parameter>
<Parameter>
<Name> URL </Name>
<Value> XYZ </value>
</Parameter>
<Parameter>
<Name> username </Name>
<Value> XYZ </value>
</Parameter>
<Parameter>
<Name> password </Name>
<Value> XYZ </value>
</Parameter>
<Parameter>
<Name> maxactive </Name>
<Value> 5 </value>
</Parameter>
<Parameter>
<Name> maxidle </Name>
<Value> 5 </value>
</Parameter>
<Parameter>
<Name> maxwait </Name>
<Value>-1 </value>
</Parameter>
<Parameter>
<Name> removeabandoned </Name>
<Value> true </value>
</Parameter>
<Parameter>
<Name> validationquery </Name>
<Value> select count (*) from sometable where 1 = 0 </value>
</Parameter>
<Parameter>
<Name> testonborrow </Name>
<Value> true </value>
</Parameter>

Proxool
<Bean id = "proxooldatasource" class = "*. proxool. proxooldatasource" Destroy-method = "close">
<Property name = "alias"> <value> newstest </value> </property>
<Property name = "driver"> <value> net. SourceForge. jtds. JDBC. Driver </value> </property>
<Property name = "driverurl"> <value> JDBC: jtds: sqlserver: // 127.0.0.1: 1433/news <value> </property>
<Property name = "user"> <value> SA </value> </property>
<Property name = "password"> <value> 1 </value> </property>
<Property name = "housekeepingsleeptime"> <value> 90000 </value> </property>
<Property name = "prototypecount"> <value> 5 </value> </property>
<Property name = "maximumconnectioncount"> <value> 100 </value> </property>
<Property name = "minimumconnectioncount"> <value> 10 </value> </property>
<Property name = "trace"> <value> true </value> </property>
<Property name = "verbose"> <value> true </value> </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.