Fixed Task related Exceptions on ShutdownHook

This commit is contained in:
Rsl1122 2019-01-14 18:19:35 +02:00
parent b0562b5fb0
commit b9dd21609d
3 changed files with 25 additions and 13 deletions

View File

@ -104,10 +104,14 @@ public class H2DB extends SQLDB {
private void startConnectionPingTask() {
stopConnectionPingTask();
// Maintains Connection.
connectionPingTask = runnableFactory.create("DBConnectionPingTask " + getType().getName(),
new KeepAliveTask(connection, () -> getNewConnection(databaseFile), logger, errorHandler)
).runTaskTimerAsynchronously(60L * 20L, 60L * 20L);
try {
// Maintains Connection.
connectionPingTask = runnableFactory.create("DBConnectionPingTask " + getType().getName(),
new KeepAliveTask(connection, () -> getNewConnection(databaseFile), logger, errorHandler)
).runTaskTimerAsynchronously(60L * 20L, 60L * 20L);
} catch (Exception ignored) {
// Task failed to register because plugin is being disabled
}
}
private void stopConnectionPingTask() {

View File

@ -104,10 +104,14 @@ public class SQLiteDB extends SQLDB {
private void startConnectionPingTask() {
stopConnectionPingTask();
// Maintains Connection.
connectionPingTask = runnableFactory.create("DBConnectionPingTask " + getType().getName(),
new KeepAliveTask(connection, () -> getNewConnection(databaseFile), logger, errorHandler)
).runTaskTimerAsynchronously(60L * 20L, 60L * 20L);
try {
// Maintains Connection.
connectionPingTask = runnableFactory.create("DBConnectionPingTask " + getType().getName(),
new KeepAliveTask(connection, () -> getNewConnection(databaseFile), logger, errorHandler)
).runTaskTimerAsynchronously(60L * 20L, 60L * 20L);
} catch (Exception ignored) {
// Task failed to register because plugin is being disabled
}
}
private void stopConnectionPingTask() {

View File

@ -90,15 +90,19 @@ public class SpongeMySQLDB extends MySQLDB {
return super.getConnection();
} catch (SQLException e) {
if (e.getMessage().contains("has been closed")) {
try {
setupDataSource();
} catch (DBInitException setupException) {
throw new IllegalStateException("Failed to set up a new datasource after connection failure.", setupException);
}
restartDataSource();
return super.getConnection();
} else {
throw e;
}
}
}
private void restartDataSource() {
try {
setupDataSource();
} catch (DBInitException setupException) {
throw new IllegalStateException("Failed to set up a new datasource after connection failure.", setupException);
}
}
}