[FEATURE] Support hikariMaxLifetime

This commit is contained in:
Gravita 2023-06-30 20:21:20 +07:00
parent d4f63a4e19
commit bd83e8a4c5
2 changed files with 5 additions and 0 deletions

View file

@ -33,6 +33,7 @@ public final class MySQLSourceConfig implements AutoCloseable, SQLSourceConfig {
private String password; private String password;
private String database; private String database;
private String timezone; private String timezone;
private long hikariMaxLifetime = 30*60*1000; // 30 minutes
private boolean useHikari; private boolean useHikari;
// Cache // Cache
@ -110,6 +111,7 @@ public synchronized Connection getConnection() throws SQLException {
hikariConfig.setConnectionTimeout(1000); hikariConfig.setConnectionTimeout(1000);
hikariConfig.setAutoCommit(true); hikariConfig.setAutoCommit(true);
hikariConfig.setLeakDetectionThreshold(2000); hikariConfig.setLeakDetectionThreshold(2000);
hikariConfig.setMaxLifetime(hikariMaxLifetime);
// Set HikariCP pool // Set HikariCP pool
// Replace source with hds // Replace source with hds
source = new HikariDataSource(hikariConfig); source = new HikariDataSource(hikariConfig);

View file

@ -27,6 +27,8 @@ public final class PostgreSQLSourceConfig implements AutoCloseable, SQLSourceCon
private String password; private String password;
private String database; private String database;
private long hikariMaxLifetime = 30*60*1000; // 30 minutes
// Cache // Cache
private transient DataSource source; private transient DataSource source;
private transient boolean hikari; private transient boolean hikari;
@ -66,6 +68,7 @@ public synchronized Connection getConnection() throws SQLException {
hikariSource.setMinimumIdle(0); hikariSource.setMinimumIdle(0);
hikariSource.setMaximumPoolSize(MAX_POOL_SIZE); hikariSource.setMaximumPoolSize(MAX_POOL_SIZE);
hikariSource.setIdleTimeout(TIMEOUT * 1000L); hikariSource.setIdleTimeout(TIMEOUT * 1000L);
hikariSource.setMaxLifetime(hikariMaxLifetime);
// Replace source with hds // Replace source with hds
source = hikariSource; source = hikariSource;