我按照此处文档中的方法创建了一个带有 servlet 部署的 undertow 服务器:
http://undertow.io/documentation/servlet/deployment.html
我现在正试图停止 servlet 中的服务器和应用程序。
调用server.stop()
使服务器在指定端口上不可用,但是当我server.start()
再次调用时,应用程序立即可用(如果它已停止,则需要一些时间才能重新启动)。我还可以看到调用时没有释放服务器的内存server.stop
。我尝试了各种组合,包括deploymentManager.undeploy()
以相同的效果调用所有组合。
我已经在文档中搜索了任何线索,但结果都是空的。我想知道其他人是否有任何线索?以下是当前状态的源代码(请注意,我不是 Java 开发人员,所以会有很多花哨的东西):
package org.locee;
import io.undertow.Undertow;
import io.undertow.Undertow.Builder;
import io.undertow.Handlers;
import io.undertow.util.Headers;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import io.undertow.server.handlers.PathHandler;
import io.undertow.server.HttpHandler;
import static io.undertow.servlet.Servlets.defaultContainer;
import javax.servlet.ServletException;
public class LoceeUndertowServer {
private DeploymentManager deploymentManager;
private Undertow undertowServer;
private DeploymentInfo servletInfo;
private int port;
private String host;
public LoceeUndertowServer( DeploymentInfo servletInfo, int port, String host ) {
this.servletInfo = servletInfo;
this.port = port;
this.host = host;
}
public void start() throws ServletException {
deploymentManager = defaultContainer().addDeployment( servletInfo );
deploymentManager.deploy();
HttpHandler httpHandler = deploymentManager.start();
PathHandler pathHandler = Handlers.path( Handlers.redirect( "/" ) ).addPrefixPath( "/", httpHandler );
Builder builder = Undertow.builder();
builder.addHttpListener( port, host );
builder.setHandler( pathHandler );
undertowServer = builder.build();
undertowServer.start();
}
public void shutdown() throws ServletException {
deploymentManager.undeploy();
defaultContainer().removeDeployment( servletInfo );
undertowServer.stop();
}
public void restart() throws ServletException {
shutdown();
start();
}
}