专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Java教程 » c3p0连接池:Spring配C3P0连接池 »正文

c3p0连接池:Spring配C3P0连接池

来源: 发布时间:星期四, 2009年1月8日 浏览:30次 评论:0
applicationContext.xml文件:<?xmlversion="1.0"encoding="UTF-8"?>  
 <beansxmlns="http://www.springframework.org/schema/beans" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:jee="http://www.springframework.org/schema/jee" 
   xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
       http://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-2.0.xsd">  
   <beanid="dataSource" 
     ="com.mchange.v2.c3p0.ComboPooledDataSource" 
     destroy-method="close">  
     <propertyname="driver">  
       <value>com.mysql.jdbc.Driver</value>  
     </property>  
     <propertyname="jdbcUrl">  
       <value>jdbc:mysql://192.168.3.110:3306/DBName?useUnicode=true&characterEncoding=GBK</value>  
     </property>  
     <propertyname="user">  
       <value>root</value>  
     </property>  
     <propertyname="password">  
       <value>root</value>  
     </property>  
 <!--连接池中保留最小连接数-->  
     <propertyname="minPoolSize">  
       <value>5</value>  
     </property>  
 <!--连接池中保留最大连接数Default:15-->  
     <propertyname="maxPoolSize">  
       <value>30</value>  
     </property>  
 <!--化时获取连接数取值应在minPoolSize和maxPoolSize的间Default:3-->  
     <propertyname="initialPoolSize">  
       <value>10</value>  
     </property>  
 <!--最大空闲时间,60秒内未使用则连接被丢弃若为0则永不丢弃Default:0-->  
     <propertyname="maxIdleTime">  
       <value>60</value>  
     </property>  
 <!--当连接池中连接耗尽时候c3p0次同时获取连接数Default:3-->  
     <propertyname="acquireIncrement">  
       <value>5</value>  
     </property>  
 <!--JDBC标准参数用以控制数据源内加载PreparedStatements数量但由于预缓存Cachestatements 属于单个connection而不是整个连接池所以设置这个参数需要考虑到多方面原因 如果maxStatements和maxStatementsPerConnection均为0则缓存Cache被关闭Default:0-->  
     <propertyname="maxStatements">  
       <value>0</value>  
     </property>  
lt;!--每60秒检查所有连接池中空闲连接Default:0-->  
     <propertyname="idleConnectionTestPeriod">  
       <value>60</value>  
     </property>  
 <!--定义在从数据库获取新连接失败后重复尝试次数Default:30-->  
     <propertyname="acquireRetryAttempts">  
       <value>30</value>  
     </property>  
 <!--获取连接失败将会引起所有等待连接池来获取连接线程抛出异常但是数据源仍有效 保留并在下次getConnection时候继续尝试获取连接如果设为true那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭Default:false-->  
     <propertyname="AfterAcquireFailure">  
       <value>true</value>  
     </property>  
 <!--因性能消耗大请只在需要时候使用它如果设为true那么在每个connection提交 时候都将校验其有效性建议使用idleConnectionTestPeriod或automaticTestTable 等思路方法来提升连接测试性能Default:false-->  
     <propertyname="testConnectionOnCheckout">  
       <value>false</value>  
     </property>  
   </bean>  
   <!--<Atitle=Hibernatehref="http://www.google.cn/search?sbi=基金&amp;amp;q=基金&amp;amp;sbb=搜索&amp;amp;sa=搜索&amp;amp;client=pub-6430022987645146&amp;amp;forid=1&amp;amp;prog=aff&amp;amp;ie=GB2312&amp;amp;oe=GB2312&amp;amp;hl=zh-CN"target=_blank>Hibernate</A>SessionFactory-->  
   <beanid="sessionFactory" 
     ="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
     <propertyname="dataSource">  
       <reflocal="dataSource"/>  
     </property>  
     <propertyname="mappingResources">  
       <list>  
         <value>com/xh/hibernate/vo/User.hbm.xml</value>  
       </list>  
     </property>  
     <propertyname="hibernateProperties">  
       <props>  
         <propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>  
         <propkey="hibernate.show_sql">true</prop>  
         <propkey="hibernate.generate_statistics">true</prop>  
         <propkey="hibernate.connection.release_mode">auto</prop>  
         <propkey="hibernate.autoReconnect">true</prop>  
       </props>  
     </property>  
   </bean>  
 </beans>


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: