Make database operations during startup consistent

Use the same Connection. and log things in a similar fashion
This commit is contained in:
P0nk
2021-04-11 13:33:22 +02:00
parent 858fcd2a3a
commit 68239bc0b5
3 changed files with 65 additions and 55 deletions

View File

@@ -19,8 +19,12 @@
*/
package net.server.task;
import java.sql.Connection;
import java.sql.SQLException;
import net.server.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.DatabaseConnection;
import tools.FilePrinter;
/**
@@ -28,13 +32,17 @@ import tools.FilePrinter;
* @info Thread responsible for maintaining coupons EXP & DROP effects active
*/
public class CouponTask implements Runnable {
private static final Logger log = LoggerFactory.getLogger(CouponTask.class);
@Override
public void run() {
try {
Server.getInstance().updateActiveCoupons();
try (Connection con = DatabaseConnection.getConnection()) {
Server.getInstance().updateActiveCoupons(con);
}
Server.getInstance().commitActiveCoupons();
} catch(SQLException sqle) {
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, "Unexpected SQL error: " + sqle.getMessage());
} catch (SQLException sqle) {
log.error("Error updating coupon effects", sqle);
}
}
}