alibaba 连接池
阿狸Druid连接池及监控在spring配置:
applicationContext.xml
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" /> <property name="username" value="test"/> <property name="password" value="test"/> <!-- 连接池启动时的初始值 --> <property name="initialSize" value="2"/> <property name="maxIdle" value="5"/> <property name="maxActive" value="150"/> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="validationQuery" value="SELECT 'x'" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <!-- 超过时间限制是否回收 --> <property name="removeAbandoned" value="true" /> <!-- 超时时间;单位为秒。180秒=3分钟 --> <property name="removeAbandonedTimeout" value="180" /> <!-- 关闭abanded连接时输出错误日志 --> <property name="logAbandoned" value="true" /> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 --> <property name="filters" value="stat" /> </bean> |
监控的配置:web.xml
监控界面 http://ip地址:端口号/项目名/自定义DruidStatView目录/index.html
或者 http://ip地址:端口号/项目名/dataSourceController.do?goDruid&isIframe
自定义DruidStatView目录建个空index.jsp
监控连接controller
package com.zy.mvc.controller; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/dataSourceController") public class DataSourceController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(DataSourceController.class); /** * 跳转到连接池监控页面 * * @return */ @RequestMapping(params = "goDruid") public ModelAndView goDruid() { return new ModelAndView("/system/druid/index"); } } |