Auto-close DB and fix server closing algorithm
This commit is contained in:
parent
3f63e2262f
commit
b914364c49
@ -60,9 +60,9 @@ public class CrabServer implements Crab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public synchronized void stop() {
|
||||||
|
isStopped = true;
|
||||||
try {
|
try {
|
||||||
isStopped = true;
|
|
||||||
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) {
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user