shutodwn hook
This commit is contained in:
@@ -33,6 +33,7 @@ public class Main {
|
||||
gameLoop.start();
|
||||
|
||||
Server server = appContext.getBean("server", Server.class);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
|
||||
try {
|
||||
server.start();
|
||||
} catch (StartServerException e) {
|
||||
|
||||
@@ -6,4 +6,5 @@ package mc.core.network;
|
||||
|
||||
public interface Server {
|
||||
void start() throws StartServerException;
|
||||
void stop();
|
||||
}
|
||||
|
||||
@@ -72,4 +72,11 @@ public class NettyServer implements Server {
|
||||
throw new StartServerException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
log.info("Server shutdown");
|
||||
workerGroup.shutdownGracefully();
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user