mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Close old and return new if connection invalid
This commit is contained in:
parent
8641bd5f0d
commit
6aae5be083
@ -81,11 +81,14 @@ public class MySQLDB extends SQLDB {
|
||||
public Connection getConnection() throws SQLException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
if (!connection.isValid(5)) {
|
||||
connection.close();
|
||||
if (dataSource instanceof HikariDataSource) {
|
||||
((HikariDataSource) dataSource).close();
|
||||
}
|
||||
try {
|
||||
setupDataSource();
|
||||
// get new connection after restarting pool
|
||||
return dataSource.getConnection();
|
||||
} catch (DBInitException e) {
|
||||
throw new DBOpException("Failed to restart DataSource after a connection was invalid: " + e.getMessage(), e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user