当前位置:网站首页>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 =100
C3P0Mysql.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 ");
}
}
边栏推荐
- Common redis data types and application scenarios
- Coding devsecops helps financial enterprises run out of digital acceleration
- How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
- What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
- Detailed explanation of usememo, memo, useref and other relevant hooks
- The difference between SQL Server char nchar varchar and nvarchar
- Brief introduction of machine learning framework
- Your childhood happiness was contracted by it
- Bugku's Ping
- P6183 [USACO10MAR] The Rock Game S
猜你喜欢
随机推荐
B站做短视频,学抖音死,学YouTube生?
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Bugku telnet
Common PHP interview questions (1) (written PHP interview questions)
Coding devsecops helps financial enterprises run out of digital acceleration
[recruitment position] Software Engineer (full stack) - public safety direction
爱可可AI前沿推介(7.5)
Shanghai under layoffs
Detailed explanation of usememo, memo, useref and other relevant hooks
Creation and optimization of MySQL index
Thymeleaf uses background custom tool classes to process text
[recruitment position] infrastructure software developer
CPU design related notes
【数组和进阶指针经典笔试题12道】这些题,满足你对数组和指针的所有幻想,come on !
maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
Reasons and solutions for redis cache penetration and cache avalanche
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
sql server学习笔记
Detailed explanation of QT creator breakpoint debugger
Install and configure Jenkins