shutodwn hook
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ package mc.core.network;
|
|||||||
|
|
||||||
public interface Server {
|
public interface Server {
|
||||||
void start() throws StartServerException;
|
void start() throws StartServerException;
|
||||||
|
void stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user