gpt4 book ai didi

java - 关闭 netty 连接会使连接处于 TIMED_WAIT 状态

转载 作者:行者123 更新时间:2023-12-01 09:55:18 29 4
gpt4 key购买 nike

我有以下代码来启动 netty 服务器:

    Application application = ApplicationTypeFactory.getApplication(type);
resteasyDeployment = new ResteasyDeployment();

// Explicitly setting the Application should prevent scanning
resteasyDeployment.setApplication(application);

// Need to set the provider factory to the default, otherwise the
// providers we need won't be registered, such as JSON mapping
resteasyDeployment.setProviderFactory(ResteasyProviderFactory.getInstance());

netty = new NettyJaxrsServer();

netty.setHostname(HOST);
netty.setPort(port);
netty.setDeployment(resteasyDeployment);

// Some optional extra configuration
netty.setKeepAlive(true);
netty.setRootResourcePath("/");
netty.setSecurityDomain(null);
netty.setIoWorkerCount(16);
netty.setExecutorThreadCount(16);

LOGGER.info("Starting REST server on: " + System.getenv("HOSTNAME") + ", port:" + port);
// Start the server
//("Starting REST server on " + System.getenv("HOSTNAME"));
netty.start();

LOGGER.info("Started!");

当我这样做时:

   netty.stop()

它似乎没有关闭连接:

[john@dub-001948-VM01:~/workspace/utf/atf/src/test/resources ]$ netstat    -anp | grep 8888
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 ::ffff:10.0.21.88:8888 ::ffff:10.0.21.88:60654 TIME_WAIT -
tcp 0 0 ::ffff:10.0.21.88:8888 ::ffff:10.0.21.88:60630 TIME_WAIT -
tcp 0 0 ::ffff:10.0.21.88:8888 ::ffff:10.0.21.88:60629 TIME_WAIT -
tcp 0 0 ::ffff:10.0.21.88:8888 ::ffff:10.0.21.88:60637 TIME_WAIT -
tcp 0 0 ::ffff:10.0.21.88:8888 ::ffff:10.0.21.88:60640 TIME_WAIT -

即使在程序退出后也是如此。在其他帖子中,我读到 netty 不会在停止时关闭客户端连接。如何彻底关闭它?

最佳答案

Time_Wait 是套接字状态之一。应用程序对此无能为力。更多信息在这里:http://www.isi.edu/touch/pubs/infocomm99/infocomm99-web/ 。对于繁忙的服务器,您可以调整一些 tcp/ip 参数来减轻其影响。

关于java - 关闭 netty 连接会使连接处于 TIMED_WAIT 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37283715/

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