gpt4 book ai didi

java - 启动或停止jetty ServerConnector而不重新启动服务器

转载 作者:行者123 更新时间:2023-11-30 01:56:05 25 4
gpt4 key购买 nike

我使用jetty服务器来处理客户端请求,并且有一个要求,我需要按需启动或停止一个或几个ServerConnector,而不重新启动这些连接器所连接的服务器。

例如。

ServerConnector httpConnector;
ServerConnector httpsConnector;
Server server;
server.addConnector(httpConnector);
server.addConnector(httpsConnector);
server.start()

需要启动/停止/取消特定连接器而不强制服务器重新启动。

最佳答案

您必须执行以下操作...

// TODO: Have a reference to the Connector you are going to work with

// Remove from server first.
server.removeConnector(connector);

// Stop the connector.
// NOTE: Existing connections will still live on.
// This will only stop accepting new connections.
connector.stop(); // might take a while (waiting for acceptors to close)

// TODO: do what you want with this connector

// Eg: harshly close existing connections
connector.getConnectedEndPoints().forEach((endpoint)-> {
endpoint.close();
});

// Re-add stopped connector if you want
// This will start connector as well
// This can fail (eg: if port is already in use)
server.addConnector(connector);

关于java - 启动或停止jetty ServerConnector而不重新启动服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54469952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com