druid mysql sleep_druid使用

Druid是阿里开源的一个为监控而生的数据库连接池,如果项目需要查看性能使用这个将可以非常清晰的看到大部分监控项目。项目地址是https://github.com/alibaba/druid

Druid是Java语言中最好的数据库连接池。Druid能够提供强大的监控和扩展功能。首先编写druid的配置文件

[code lang=”js”]

driverClassName=com.mysql.jdbc.Driver

url=jdbc:mysql://localhost:3306/bobodb?createDatabaseIfNotExist=true&autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8

username=xxxx

password=xxxxxxxx

filters=stat

initialSize=2

maxActive=300

maxWait=60000

timeBetweenEvictionRunsMillis=60000

minEvictableIdleTimeMillis=300000

validationQuery=SELECT 1

testWhileIdle=true

testOnBorrow=false

testOnReturn=false

poolPreparedStatements=false

maxPoolPreparedStatementPerConnectionSize=200

connectionProperties=druid.stat.mergeSql\=true

[/code]

然后创建连接池

[code lang=”js”]

static {

try {

Properties properties = new Properties();

properties.load(DBConnection.class.getClassLoader().getResourceAsStream("druid.properties"));

dataSource = DruidDataSourceFactory.createDataSource(properties);

} catch (Exception e) {

logger.error("初始化数据库连接异常:{}", e.getMessage()); //$NON-NLS-1$

e.printStackTrace();

}

}

[/code]

获取连接

[code lang=”js”]

Connection conn = null;

try {

conn = dataSource.getConnection();

} catch (Exception e) {

logger.error("获取Mysql数据库连接异常:{}", e.getMessage()); //$NON-NLS-1$

e.printStackTrace();

}

[/code]

配置url监控(web.xml)

[code lang=”js”]

DruidStatView

com.alibaba.druid.support.http.StatViewServlet

DruidStatView

/druid/*

DruidWebStatFilter

com.alibaba.druid.support.http.WebStatFilter

exclusions

*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*

DruidWebStatFilter

/*

[/code]

其他更详细的配置可以参照官网文档

https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

打开http://localhost:8080/QLBoboService/druid/sql.html可以看到效果

–每天一点点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值