当前位置:网站首页>Usage and usage instructions of JDBC connection pool
Usage and usage instructions of JDBC connection pool
2022-07-05 15:17:00 【Add gold development】
We all know through jdbc Link to Will consume a lot of connections , Every connection consumes resources , close 》 Opening it will consume resources , Build up... Frequently 、 Close the connection , It will greatly reduce the performance of the system , Because the use of connections becomes the bottleneck of system performance .
Advantages brought by database connection pool technology :
1. Resource reuse
2. Faster system response time
3. New means of resource allocation
4. Unified connection management , Avoid database connection leaks
Principle diagram

Using process :
jdbc.properties
DriverClass = com.mysql.jdbc.Driver
JdbcUrl = jdbc\:mysql\://ID\:3306/htmldata?useUnicode\=true&characterEncoding\=UTF-8
User = root
Password = 123
MaxPoolSize = 20
MinPoolSize = 2
InitialPoolSize = 5
MaxStatements = 30
MaxIdleTime =100C3P0Mysql.java
package class_name;
import java.sql.Connection;
import java.util.Properties;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class C3P0Mysql {
private ComboPooledDataSource cpds;
private static C3P0Mysql c3P0Properties;
static{
c3P0Properties = new C3P0Mysql();
}
public C3P0Mysql() {
try {
cpds = new ComboPooledDataSource();
// Load profile
Properties props = new Properties();
props.load(C3P0Mysql.class.getClassLoader().getResourceAsStream("jdbc.properties"));
cpds.setDriverClass(props.getProperty("DriverClass"));
cpds.setJdbcUrl(props.getProperty("JdbcUrl"));
cpds.setUser(props.getProperty("User"));
cpds.setPassword(props.getProperty("Password"));
cpds.setMaxPoolSize(Integer.parseInt(props.getProperty("MaxPoolSize")));
cpds.setMinPoolSize(Integer.parseInt(props.getProperty("MinPoolSize")));
cpds.setInitialPoolSize(Integer.parseInt(props.getProperty("InitialPoolSize")));
cpds.setMaxStatements(Integer.parseInt(props.getProperty("MaxStatements")));
cpds.setMaxIdleTime(Integer.parseInt(props.getProperty("MaxIdleTime")));
} catch (Exception e) {
e.printStackTrace();
}
}
public static C3P0Mysql getInstance(){
return c3P0Properties;
}
public Connection getConnection(){
Connection conn = null;
try {
conn = cpds.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection connection = C3P0Mysql.c3P0Properties.getConnection();
System.out.println(" Connected successfully ");
}
}
边栏推荐
- P6183 [USACO10MAR] The Rock Game S
- I include of spring and Autumn
- 想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
- go学习 ------jwt的相关知识
- B站做短视频,学抖音死,学YouTube生?
- What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
- MongDB学习笔记
- Talk about your understanding of microservices (PHP interview theory question)
- Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
- Creation and use of thymeleaf template
猜你喜欢

Bugku's Eval

Ctfshow web entry command execution

B站做短视频,学抖音死,学YouTube生?

12 MySQL interview questions that you must chew through to enter Alibaba

I include of spring and Autumn

MongDB学习笔记

Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发

Run faster with go: use golang to serve machine learning

ionic cordova项目修改插件

sql server学习笔记
随机推荐
Bugku's eyes are not real
MongDB学习笔记
你童年的快乐,都是被它承包了
漫画:优秀的程序员具备哪些属性?
Stm32+bh1750 photosensitive sensor obtains light intensity
MySQL之CRUD
Redis distributed lock principle and its implementation with PHP (1)
JMeter performance test: serveragent resource monitoring
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
可转债打新在哪里操作开户是更安全可靠的呢
CODING DevSecOps 助力金融企业跑出数字加速度
SQL Server learning notes
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
mapper.xml文件中的注释
sql server学习笔记
easyOCR 字符識別
Aike AI frontier promotion (7.5)
PHP high concurrency and large traffic solution (PHP interview theory question)
Magic methods and usage in PHP (PHP interview theory questions)
【jvm】运算指令