mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-12 11:21:16 +01:00
Fixed Task related Exceptions on ShutdownHook
This commit is contained in:
parent
b0562b5fb0
commit
b9dd21609d
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user