BeeCP is a high-performance JDBC connection pool
Java7 or higher
<dependency>
<groupId>com.github.chris2018998</groupId>
<artifactId>beecp</artifactId>
<version>3.3.0</version>
</dependency>
Java6
<dependency>
<groupId>com.github.chris2018998</groupId>
<artifactId>beecp</artifactId>
<version>1.6.10</version>
</dependency>
1:Single connection threadLocal cache to improve pooling performance
2:Borrower non move waiting, saving queue entry and exit costs
3: Transfer queue reuse, which can transfer connections and exceptions
4:Connection asynchronized-add thread,which can be triggerred by releaser or waiter
Item | BeeCP | HikariCP |
---|---|---|
Key | ThreadLocal + semaphore+ ConcurrentLinkedQueue +Thread | FastList + ConcurrentBag + ThreadPoolExecutor |
Similarity | CAS,Proxy pre-generation,Driver statement cache,Jmx | |
Difference | Balance mode,Hold-timeout,Support XA,Pool clean | Pool suspend,Config runtime change |
File | 32 source files,Jar package 93KB | 44 source files,Jar package 158KB |
Performance | Higher than 40% |
Which defects of HikariCP?
1:Closed preparedStatements can be activation, when using MySQ-driver
3:Exists transaction leak,when using 'setSavepoint' on connection
.....
Conclusion: faster, simpler, reliabler
Its usage is roughly similar to other pool, two reference examples below
BeeDataSourceConfig config = new BeeDataSourceConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setJdbcUrl("jdbc:mysql://localhost/test");
config.setUsername("root");
config.setPassword("root");
BeeDataSource ds=new BeeDataSource(config);
Connection con=ds.getConnection();
....
application.properties
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.driverClassName=com.mysql.jdbc.Driver
DataSourceConfig.java
@Configuration
public class DataSourceConfig {
@Value("${spring.datasource.username}")
private String user;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.driverClassName}")
private String driver;
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().type(cn.beecp.BeeDataSource.class).build();
}
}
☀️ If your projects are based on springboot, we recommend BeeCP-Starter to manage your datasource(file configuration, less code, monitor-ui)
If not configured, auto generated
Boolean indicator,if true,pool will use fair semaphore and fair transfer policy. default value: false
Size of connections on pool starting,if zero,pool will try to create one.default value: 0
Max reach size of connections in pool.default value: 10
Size of semaphore in pool. default value: number of CPU cores
Value setting on conneciton creating and return, default value: true
Value setting on conneciton creating and return. default value: -999,if not set then read value from first connection
Max wait time for one connection for borrower using 'getConnection'. unit: milliseconds, default value: 8000
Max idle time of connections in pool,when reach,then remove from pool.unit: milliseconds, default value: 18000
Max no-use time of borrowed connections,when reach,then return them to pool by forced close.unit: milliseconds, default value: 18000
Connection valid test sql on borrowed. default value: SELECT 1
Max time to get a valid test result. unit:second, default value: 3
Conenction valid assume time after last activity,if borrowed,not need test during the duration.unit: milliseconds, default value: 500