Compare commits

...

2 Commits

Author SHA1 Message Date
488a3f4e54 Merge branch 'master' of https://gitea.bedohswe.eu.org/pixtaded/crab
Merge with local changes
2025-01-10 23:48:07 +03:00
b914364c49 Auto-close DB and fix server closing algorithm 2025-01-10 23:47:19 +03:00
2 changed files with 9 additions and 3 deletions

View File

@ -66,9 +66,9 @@ public class CrabServer implements Crab {
} }
} }
public void stop() { public synchronized void stop() {
try {
isStopped = true; isStopped = true;
try {
if (socket != null) socket.close(); if (socket != null) socket.close();
if (serverSocket != null) serverSocket.close(); if (serverSocket != null) serverSocket.close();
} catch (IOException e) { } catch (IOException e) {

View File

@ -6,7 +6,7 @@ import java.sql.*;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
public class Database { public class Database implements AutoCloseable {
private Connection connection; private Connection connection;
private String logs = ""; private String logs = "";
@ -68,4 +68,10 @@ public class Database {
else return logs.getBytes().length; else return logs.getBytes().length;
} }
@Override
public void close() throws SQLException {
if (connection != null && !connection.isClosed()) {
connection.close();
}
}
} }