This commit is contained in:
Jesse Boyd 2016-11-24 10:19:00 +11:00
parent 9fd53af483
commit 8ebf71c87f
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -135,7 +135,7 @@ public class SQLManager implements AbstractDB {
boolean hasTask = !globalTasks.isEmpty() || !playerTasks.isEmpty() || !plotTasks.isEmpty() || !clusterTasks.isEmpty(); boolean hasTask = !globalTasks.isEmpty() || !playerTasks.isEmpty() || !plotTasks.isEmpty() || !clusterTasks.isEmpty();
if (hasTask) { if (hasTask) {
try { try {
if (SQLManager.this.mySQL && System.currentTimeMillis() - last > 550000 || !connection.isValid(10000)) { if (SQLManager.this.mySQL && System.currentTimeMillis() - last > 550000 || !isValid()) {
last = System.currentTimeMillis(); last = System.currentTimeMillis();
reconnect(); reconnect();
} }
@ -167,6 +167,15 @@ public class SQLManager implements AbstractDB {
}); });
} }
public boolean isValid() {
try (PreparedStatement stmt = this.connection.prepareStatement("SELECT 1")) {
stmt.executeQuery();
return true;
} catch (Throwable e) {
return false;
}
}
public void reconnect() { public void reconnect() {
try { try {
close(); close();