mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FIX] Backport 62991ed709
This commit is contained in:
parent
9f5810fad6
commit
853595e576
1 changed files with 14 additions and 9 deletions
|
@ -30,8 +30,8 @@ public final class MySQLSourceConfig implements AutoCloseable {
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
private String database;
|
private String database;
|
||||||
private String timeZone;
|
private String timezone;
|
||||||
private boolean enableHikari;
|
private boolean useHikari;
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
private transient DataSource source;
|
private transient DataSource source;
|
||||||
|
@ -91,21 +91,26 @@ public synchronized Connection getConnection() throws SQLException {
|
||||||
mysqlSource.setPassword(password);
|
mysqlSource.setPassword(password);
|
||||||
mysqlSource.setDatabaseName(database);
|
mysqlSource.setDatabaseName(database);
|
||||||
mysqlSource.setTcpNoDelay(true);
|
mysqlSource.setTcpNoDelay(true);
|
||||||
if (timeZone != null) mysqlSource.setServerTimezone(timeZone);
|
if (timezone != null) mysqlSource.setServerTimezone(timezone);
|
||||||
hikari = false;
|
hikari = false;
|
||||||
// Try using HikariCP
|
// Try using HikariCP
|
||||||
source = mysqlSource;
|
source = mysqlSource;
|
||||||
if (enableHikari) {
|
if (useHikari) {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.zaxxer.hikari.HikariDataSource");
|
Class.forName("com.zaxxer.hikari.HikariDataSource");
|
||||||
hikari = true; // Used for shutdown. Not instanceof because of possible classpath error
|
hikari = true; // Used for shutdown. Not instanceof because of possible classpath error
|
||||||
HikariConfig cfg = new HikariConfig();
|
HikariConfig hikariConfig = new HikariConfig();
|
||||||
cfg.setDataSource(mysqlSource);
|
hikariConfig.setDataSource(mysqlSource);
|
||||||
cfg.setPoolName(poolName);
|
hikariConfig.setPoolName(poolName);
|
||||||
cfg.setMaximumPoolSize(MAX_POOL_SIZE);
|
hikariConfig.setMinimumIdle(1);
|
||||||
|
hikariConfig.setMaximumPoolSize(MAX_POOL_SIZE);
|
||||||
|
hikariConfig.setConnectionTestQuery("SELECT 1");
|
||||||
|
hikariConfig.setConnectionTimeout(1000);
|
||||||
|
hikariConfig.setAutoCommit(true);
|
||||||
|
hikariConfig.setLeakDetectionThreshold(2000);
|
||||||
// Set HikariCP pool
|
// Set HikariCP pool
|
||||||
// Replace source with hds
|
// Replace source with hds
|
||||||
source = new HikariDataSource(cfg);
|
source = new HikariDataSource(hikariConfig);
|
||||||
LogHelper.warning("HikariCP pooling enabled for '%s'", poolName);
|
LogHelper.warning("HikariCP pooling enabled for '%s'", poolName);
|
||||||
} catch (ClassNotFoundException ignored) {
|
} catch (ClassNotFoundException ignored) {
|
||||||
LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName);
|
LogHelper.debug("HikariCP isn't in classpath for '%s'", poolName);
|
||||||
|
|
Loading…
Reference in a new issue