标签:
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"> <!– Connection Info –> < property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!– Connection Pooling Info –> < property name="initialSize" value="${tomcat.pool.initialSize.common}" /> <property name="maxActive" value="${tomcat.pool.maxActive.common}" /> <property name="maxIdle" value="${tomcat.pool.maxIdle.common}" /> <property name="minIdle" value="${tomcat.pool.minIdle.common}" /> <property name="maxWait" value="${tomcat.pool.maxWait.common}" /> <property name="testWhileIdle" value="${tomcat.pool.testWhileIdle.common}" /> <property name="validationQuery" value="${tomcat.pool.validationQuery.common}" /> <property name="validationQueryTimeout" value="${tomcat.pool.validationQueryTimeout.common}" /> <property name="validationInterval" value="${tomcat.pool.validationInterval.common}" /> <property name="timeBetweenEvictionRunsMillis" value="${tomcat.pool.timeBetweenEvictionRunsMillis.common}" /> <property name="minEvictableIdleTimeMillis" value="${tomcat.pool.minEvictableIdleTimeMillis.common}" /> <property name="numTestsPerEvictionRun" value="${tomcat.pool.numTestsPerEvictionRun.common}" /> <property name="removeAbandoned" value="${tomcat.pool.removeAbandoned.common}" /> <property name="removeAbandonedTimeout" value="${tomcat.pool.removeAbandonedTimeout.common}" /> <property name="defaultAutoCommit" value="true" /> </bean>
#MySql jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://192.168.1.15:3306/common?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull jdbc.username=root jdbc.password=1921 #tomcatpool – common #初始化连接: 连接池启动时创建的初始化连接数量 tomcat.pool.initialSize.common=5 #最大活动连接: 连接池在同一时间能够分配的最大活动连接的数量,如果设置为非正数则表示不限制 tomcat.pool.maxActive.common=60 #最大空闲连接: 连接池中容许保持空闲状态的最大连接数量, 超过的空闲连接将被释放, 如果设置为负数表示不限制 tomcat.pool.maxIdle.common=10 #最小空闲连接: 连接池中容许保持空闲状态的最小连接数量, 低于这个数量将创建新的连接, 如果设置为0则不创建.默认与initialSize相同 tomcat.pool.minIdle.common=5 # 最大等待时间: 当没有可用连接时, 连接池等待连接被归还的最大时间( 以毫秒计数), 超过时间则抛出异常, 如果设置为-1 表示无限等待单位毫秒 tomcat.pool.maxWait.common=5000 #是否对空闲连接进行校验,如果检测失败, 则连接将被从池中去除.注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串 tomcat.pool.testWhileIdle.common=true #SQL 查询, 用来验证从连接池取出的连接 tomcat.pool.validationQuery.common=SELECT 1 #校验查询超时时间以秒为单位 tomcat.pool.validationQueryTimeout.common=10 #避免过度验证,保证验证不超过这个频率——以毫秒为单位 tomcat.pool.validationInterval.common=30000 #空闲连接回收器执行间隔,单位毫秒 tomcat.pool.timeBetweenEvictionRunsMillis.common=31000 #空闲连接能够保持空闲的最小时间,单位毫秒,在这个区间不会被回收器回收 tomcat.pool.minEvictableIdleTimeMillis.common=120000 #空闲连接回收器的执行线程数 tomcat.pool.numTestsPerEvictionRun.common=10 #检查连接是否泄漏(一般是因为没有关闭连接),如果他们超过了removeAbandonedTimout 的限制.如果设置为true, 连接被认为是被泄露并且可以被删除, tomcat.pool.removeAbandoned.common=true #连接多久没有释放则认为是泄漏线程 tomcat.pool.removeAbandonedTimeout.common=180
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3309/sampledb" /> <property name="username" value="root" /> <property name="password" value="1234" /> </bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value=" oracle.jdbc.driver.OracleDriver "/> <property name="jdbcUrl" value=" jdbc:oracle:thin:@localhost:1521:ora9i "/> <property name="user" value="admin"/> <property name="password" value="1234"/> </bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="/WEB-INF/jdbc.properties"/> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean>
jdbc.driverClassName= com.mysql.jdbc.Driver jdbc.url= jdbc:mysql://localhost:3309/sampledb jdbc.username=root jdbc.password=1234
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/bbt"/> </bean>
<beans xmlns=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/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"> <jee:jndi-lookup id="dataSource" jndi-name=" java:comp/env/jdbc/bbt"/> </beans>
DriverManagerDataSource ds = new DriverManagerDataSource (); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUrl("jdbc:mysql://localhost:3309/sampledb"); ds.setUsername("root"); ds.setPassword("1234"); Connection actualCon = ds.getConnection();
proxool 数据源
maven 信息:
<!-- proxool连接池 --> <dependency> <groupId>com.cloudhopper.proxool</groupId> <artifactId>proxool</artifactId> <version>0.9.1</version> </dependency>
<bean id="proxoolDataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource"> <property name="driver" value="${jdbc.connection.driverClassName}"/> <property name="driverUrl" value="${jdbc.connection.url}"/> <property name="user" value="${jdbc.connection.username}"/> <property name="password" value="${jdbc.connection.password}"/> <!-- 测试的SQL执行语句 --> <property name="houseKeepingTestSql" value="${proxool.houseKeepingTestSql}"/> <!-- 最少保持的空闲连接数 (默认2个) --> <property name="prototypeCount" value="${proxool.prototypeCount}"/> <!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒) --> <property name="houseKeepingSleepTime" value="${proxool.hourseKeepingSleepTime}"/> <!-- 最大活动时间(超过此时间线程将被kill,默认为5分钟) --> <property name="maximumActiveTime" value="${proxool.maximumActiveTime}"/> <!-- 连接最长时间(默认为4个小时) --> <property name="maximumConnectionLifetime" value="${proxool.maximumConnectionLifetime}"/> <!-- 最小连接数 (默认2个) --> <property name="minimumConnectionCount" value="${proxool.minimumConnectionCount}"/> <!-- 最大连接数 (默认5个) --> <property name="maximumConnectionCount" value="${proxool.maximumConnectionCount}"/> <!-- --> <property name="statistics" value="${proxool.statistics}"/> <!-- 别名 --> <property name="alias" value="${proxool.alias}"/> <!-- --> <property name="simultaneousBuildThrottle" value="${proxool.simultaneous-build-throttle}"/> </bean>
<?xml version="1.0" encoding="UTF-8"?> <proxool> <alias>WMS</alias> <driver-url>jdbc:postgresql://192.168.210.184:5432/wms</driver-url> <driver-class>org.postgresql.Driver</driver-class> <driver-properties> <property name="user" value="wms_user" /> <property name="password" value="wms" /> </driver-properties> <minimum-connection-count>2</minimum-connection-count> <maximum-connection-count>40</maximum-connection-count> <simultaneous-build-throttle>20</simultaneous-build-throttle> <prototype-count>2</prototype-count> <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql> </proxool>
maximum-connection-lifetime -〉连接最大生命时间 默认4小时
向 web.xml 中添加 proxool初始化设置servlet 。 即 添加如下内容:
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.configuration.ServletConfigurator
</servlet-class>
<init-param>
<param-name>propertyFile</param-name>
<param-value>WEB-INF/Proxool.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
如果想要监控 proxool 连接池信息,可以加如下信息。 输入http://localhost:8080/PoolTest/admin.proxool 即可看见
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/admin.proxool</url-pattern>
</servlet-mapping>
标签:
原文地址:http://blog.csdn.net/fs_hawkish/article/details/51813899