RK
public GambleServer(ServerSocket serverSocket,
ExecutorService threadPool,
ClientManagerFactory clientManagerFactory) {
this.serverSocket = serverSocket;
this.threadPool = threadPool;
this.clientManagerFactory = clientManagerFactory;
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}));
}
Вот пример кода.