Archived
0

shutodwn hook

This commit is contained in:
2018-04-26 21:43:35 +03:00
parent 0a699d2ad8
commit 6f7f2ad813
3 changed files with 9 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ public class Main {
gameLoop.start(); gameLoop.start();
Server server = appContext.getBean("server", Server.class); Server server = appContext.getBean("server", Server.class);
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
try { try {
server.start(); server.start();
} catch (StartServerException e) { } catch (StartServerException e) {

View File

@@ -6,4 +6,5 @@ package mc.core.network;
public interface Server { public interface Server {
void start() throws StartServerException; void start() throws StartServerException;
void stop();
} }

View File

@@ -72,4 +72,11 @@ public class NettyServer implements Server {
throw new StartServerException(e); throw new StartServerException(e);
} }
} }
@Override
public void stop() {
log.info("Server shutdown");
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
}
} }