HikariCP连接池配置

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

HikariCP号称性能最好的Java数据库连接池。虽没做过亲测但是公司项目一直在用,大概经历过2万左右用户同时在线,链接池性能方面未出现问题。

官网:http://brettwooldridge.github.io/HikariCP/

例子已上传码云:https://gitee.com/imlichao/HikariCP-example

 

安装

maven 坐标(这是java8的坐标,对应不同版本的jdk需要使用不同的版本)

<dependency><groupId>com.zaxxer</groupId><artifactId>HikariCP</artifactId><version>2.7.6</version>
</dependency>

 

配置

增加HikariCP配置文件,设置连接池配置

package pub.lichao.test.config;import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.sql.DataSource;/*** HikariCP连接池配置*/
@Configuration
public class DataSourceConfig {@Value("${spring.datasource.url}")private String dataSourceUrl;@Value("${spring.datasource.username}")private String user;@Value("${spring.datasource.password}")private String password;@Beanpublic DataSource primaryDataSource() {HikariConfig config = new HikariConfig();config.setJdbcUrl(dataSourceUrl); //数据源config.setUsername(user); //用户名config.setPassword(password); //密码config.addDataSourceProperty("cachePrepStmts", "true"); //是否自定义配置,为true时下面两个参数才生效config.addDataSourceProperty("prepStmtCacheSize", "250"); //连接池大小默认25,官方推荐250-500config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); //单条语句最大长度默认256,官方推荐2048config.addDataSourceProperty("useServerPrepStmts", "true"); //新版本MySQL支持服务器端准备,开启能够得到显著性能提升config.addDataSourceProperty("useLocalSessionState", "true");config.addDataSourceProperty("useLocalTransactionState", "true");config.addDataSourceProperty("rewriteBatchedStatements", "true");config.addDataSourceProperty("cacheResultSetMetadata", "true");config.addDataSourceProperty("cacheServerConfiguration", "true");config.addDataSourceProperty("elideSetAutoCommits", "true");config.addDataSourceProperty("maintainTimeStats", "false");HikariDataSource ds = new HikariDataSource(config);return ds;}
}

SpringBoot application.properties中配置数据源参数(具体参数含义请参考spring boot相关说明)

# Server HTTP port.
server.port=8090spring.datasource.url=jdbc:mysql://rdso30006c33s57oufvfo.mysql.rds.aliyuncs.com:3306/pltx-test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=*******
spring.datasource.password=*******
spring.datasource.driverClassName=com.mysql.jdbc.Driverspring.datasource.max-idle=10
spring.datasource.max-active=15
spring.datasource.max-lifetime=86430000
spring.datasource.log-abandoned=true
spring.datasource.remove-abandoned=true
spring.datasource.remove-abandoned-timeout=60
spring.datasource.initialize=false
spring.datasource.sqlScriptEncoding=UTF-8

连接数的确定可以参考:https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing

 

启动项目我们可以看到项目使用了HikariCP连接池

143733_LGTh_3452433.png

 

 

 

转载于:https://my.oschina.net/u/3452433/blog/1607850

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278587.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Microsoft Desktop Player是IT Pro的宝贵工具

If you are an IT Professional, a new education tool introduced by Microsoft is the MS Desktop Player. Today we take a look at what it has to offer, from Webcasts, White Papers, Training Videos, and more. 如果您是IT专业人员&#xff0c;则Microsoft推出的新的培…

如何在Microsoft Excel中将文本转换为日期值

Analysis of business data often requires working with date values in Excel to answer questions such as “how much money did we make today” or “how does this compare to the same day last week?” And that can be hard when Excel doesn’t recognize the valu…

看着手机会让您晕眩吗? 禁用动画

Giulio_Fornasar/ShutterstockGiulio_Fornasar /快门Are your phone’s buttery-smooth animations causing motion sickness, eyestrain, or even slow app performance? Those animations are just for looks, and you can disable a lot of them on both iPhone and Androi…

电脑的组成

一、按电脑组成分 1.CPU&#xff08;中央处理器&#xff09;&#xff0c;是一块超大规模的集成电路&#xff0c;有很多针脚&#xff0c;是电脑的核心&#xff0c;它是电脑进行运算和控制的核心&#xff0c;处理着各种信息的运算&#xff0c;就像人计算数学题要用头脑运算一样。…

微信小程序之 SideBar(侧栏分类)

项目目录&#xff1a; 模拟数据&#xff1a; utils / data.js function getSData() {var data [{"id": 1,"tree": {"id": 1,"desc": "宝宝奶粉","desc2": null,"level": "level1","log…

如何在线查找成千上万的免费电子书

You’ve got an ebook reader (or a laptop or netbook with ebook reading software) now you just need some free books to put it to good use. Read on as we show you the best places to score free books online. 您已经有了一个电子书阅读器(或带有电子书阅读软件的笔…

Spring Bean默认配置为单实例 Spring Bean生命周期

2019独角兽企业重金招聘Python工程师标准>>> Spring 的Bean默认的是单例的. 如果不想单例需要如下配置&#xff1a; <bean id"user" class"..." scope"singleton"/> scope"singleton"就是配置这个bean是单例的&#…

minecraft服务器_如何启动自己的Minecraft服务器进行多人游戏

minecraft服务器If you’ve played Minecraft, then it’s easy to see how much fun it can be. Running your own server lets you bring all of your friends into the same game, and you can play with rules you get to make or break. It’s the ultimate in an already…

Spring Boot 2.x(六):优雅的统一返回值

目录 为什么要统一返回值ReturnVOReturnCode使用ReturnVO使用AOP进行全局异常的处理云撸猫公众号为什么要统一返回值 在我们做后端应用的时候&#xff0c;前后端分离的情况下&#xff0c;我们经常会定义一个数据格式&#xff0c;通常会包含code&#xff0c;message&#xff0c;…

jhope代码分析以及网站结构

如下图所示&#xff0c;为Extjs部分代码提供的网页结构&#xff1a;网站看上去本来是这样的前端采用ExtJS&#xff0c;与后台的SpringMVCSpringHibernate进行数据交互。之前分析过登录的过程&#xff0c;不赘述在loginController处理登录返回结果的最后&#xff0c;如下语句也就…

Ubuntu下Authentication token manipulation error或者Authentication Failure解决办法

在Ubuntu18.04使用以下命令出现以下错误: 用passwd为新建用户或者root添加密码:Authentication token manipulation error 切换root用户出现Authentication Failure. 网上出现了大致两种方法: 第一种&#xff1a;用户文件和密码文件被保护&#xff0c;用chattr命令移除保护即可…

初学者:如何使用虚拟PC将Windows 7安装到虚拟机

Continuing in our series covering how to use Virtual PC, this week we’ll be showing you how to install Windows 7 into a virtual machine. It’s a very simple process, but here’s the step-by-step guide for beginners. 继续我们的系列文章&#xff0c;介绍如何使…

arcgis本地服务快速迁移到新机

情景 在本机或服务器发布了几十、几百个gis服务&#xff0c;当换电脑或者换服务器时不可能挨个找源文件重新发布服务&#xff0c;于是就想着既然是本地文件&#xff0c;一定可以拷贝过去的&#xff0c;经过一番搜索&#xff0c;结果如下: 方案一、迁移至新站点 新机站点创建…

极客大佬用什么电脑_极客特惠:笔记本电脑,高清电视和免费应用

极客大佬用什么电脑If you love new gear but not high prices then we’ve got some deals for you; grab some deeply discounted laptops, monitors and HDTVs, and free mobile apps in this week’s Geek Deals roundup. 如果您喜欢新设备&#xff0c;但不喜欢高价&#x…

ppt插入html(用office而不是wps)

最近新get到的技能&#xff0c;在ppt里面插入html&#xff01;注意要用 Microsoft Office PowerPoint 才行&#xff0c;而不是wps&#xff0c;一定要先安装Microsoft Office PowerPoint再执行以下操作。 1、修改注册表的值&#xff0c;才能在PowerPoint中插入 Microsoft Web B…

如何使用SkyDrive的25 GB作为映射驱动器以方便访问

SkyDrive is an online storage system included in Windows Live, which gives you 25 GB of space that you can sync to your desktop. Here’s how to connect it to your Windows 7 computer as a mapped drive. SkyDrive是Windows Live中包含的一个在线存储系统&#xff…

SpringBoot+Mybatis 框架之 @SelectProvider注解方式搭建

之前搭建了Select标签来做SringBootMybatis的集成。这次使用SelectProvider标签的方式搭建一次。 一、搭建SpringBoot的项目 https://start.spring.io/自己配置SpringBoot的项目&#xff0c;点击“Generate Project”按钮就可以下载下来一个配置好的SpringBoot项目。 二、项目结…

从购买域名到nginx,flask搭建自己的网站

搭建一个只属于自己的网站? 一、注册域名&#xff08;可选*&#xff09; 1.注册阿里云账号 网址&#xff1a;登录&#xff08;注册&#xff09; 2.购买域名&#xff1a;阿里云域名注册 有一元域名、免费域名等。 购买过程中需要创建信息模板&#xff08;必须完成邮箱真实…

alexa语音实现_如何通过语音删除Alexa录音

alexa语音实现Amazon亚马孙Amazon is rolling out new privacy features today for Alexa. In addition to an educational “privacy hub,” the company lets you delete your stored recordings by voice. But it’s off by default; you’ll need to flip a switch. 亚马逊…

用scrapy框架写爬虫

爬虫可以发送给引擎的两种请求&#xff1a; # 1、url&#xff1a;# &#xff08;爬虫&#xff09;yield scrapy.Request -> 引擎 -> 调度器&#xff08;发送给调度器入队&#xff09; -> 引擎&#xff08;调度器出队请求于引擎&#xff09;# -> 下载器&#xff08;…