Configure C3P0 connection pool in spring

Source: Internet
Author: User
Tags time interval

Although DBCP is a widely used connection pool, I think that C3P0 has higher performance and stability on Tomcat. Here's how to use C3P0 in spring:

<bean id= "DataSource"    class= "Com.mchange.v2.c3p0.ComboPooledDataSource"    Destroy-method= "Close" >           <property name= " Driverclass "   value=" Oracle.jdbc.OracleDriver " />            <property name= "Jdbcurl"    value= "Jdbc:oracle:thin: @localhost: hzkj"  / >           <property name= "user"  value= "LYR"  />           <property name= "Password"   Value= "123456"  />           <!--when the connection in the connection pool is exhausted, C3P0 the number of new connections created at once-->           <property name= " Acquireincrement " value="  />           <!- -  definition to get new connections from the databaseThe number of times the attempt was repeated after the failure, by default 30-->           <property name= " Acquireretryattempts " value="  />            <!--  Two-time interval, unit milliseconds, default 1000 -->            <property name= "Acquireretrydelay"  value= "1000"  />            <!--The default to rollback all uncommitted operations when the connection is closed. Default is false -->           <property name= " Autocommitonclose " value=" false " />            <!--  Getting a connection failure will cause all threads waiting to get the connection to throw an exception. However, the data source remains valid and continues to attempt to get the connection the next time you tune    use Getconnection (). If set to True, the data source will be declared disconnected and permanently closed after the attempt to acquire the connection fails. Default to  false; -->           <property name= "Breakafteracquirefailure"  value= "false"/>           <!--  time when the client calls getconnection () after the connection pool is exhausted and waits for a new connection to be fetched , the SqlException is thrown after the timeout, and waits indefinitely if set to 0. Unit milliseconds, defaults to 0; -->           <property name= " Checkouttimeout " value=" 0 " />           <!-- The number of connections created when   is started should be evaluated between minpoolsize and Maxpoolsize. Default is 3;-->           <property name= "initialPoolSize " value="  />           <!--  Maximum free time, Connections that exceed the idle time are discarded. 0 or negative numbers will never be discarded. Default is 0; -->           <property name= " MaxIdleTime " value=" 10000 " />           <!-- The maximum number of connections that are reserved in the   connection pool. Default is 15-->           <property name= "MaxPoolSize"  value=  />           <!-- jdbc standard parameters, Used to control the number of PreparedStatement loaded in the data source. However, because the statement of the cache is    to a single connection instead of the entire connection pool. So setting this parameter takes into account a number of factors, and if both the maxstatements and    maxstatementsperconnection are 0, the cache is closed. Default is 0; -->           <property name= " Maxstatements " value=" 0 " />           <!--   The maximum number of cached statement that a single connection has within a connection pool. Default is 0;  -->           <property name= " Maxstatementsperconnection " value=" 0 " />            <!--c3p0 are asynchronous operations, and slow JDBC operations are accomplished through the help process. Extending these operations can effectively improve performance, and multiple operations through multithreading are implemented simultaneously. Default is 3; -->           <property name= " Numhelperthreads " value=" 3 " />           <!--  User modifies the maximum number of seconds to wait before the system configuration parameters are executed. Default is 300; -->           <property name= " Propertycycle " value="  />       </bean>   The following are the contents of the actual application.xml: <context:component-scan base-package= "Cn.hzkj.khSystem"/>
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >
<property name= "Driverclass" value= "Oracle.jdbc.OracleDriver"/>
<property name= "Jdbcurl" value= "jdbc:oracle:thin:@192.168.0.57:1521:hzkj"/>
<property name= "user" value= "Lyr"/>
<property name= "Password" value= "admin"/> </bean>

<bean id= "Sessionfactory"
class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name= "DataSource" >
<ref bean= "DataSource"/>
</property>
<property name= "Hibernateproperties" >
<props>
<prop key= "Hibernate.dialect" >
Org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key= "Hibernate.show_sql" >false</prop>
</props>
</property> <property name= "Mappingresources" >
<list>
    <value>cn/hzkj/common/entity/CityRoadInfo.hbm.xml</value> </list>  &nb

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.