Spring 集成 TCP - 完全关闭监听套接字的好方法是什么

Spring Integration TCP - What is a good way to close listening socket completely

使用这个选项好吗

AbstractServerConnectionFactory.closeCOnnection(ClientConnId)。我正在使用它,但发生的事情是,经过几天的处理,服务器开始出现 "too many open files" 错误。我通过 运行 命令 "lsof" 和“/proc/pid/fd” 调查了这个问题,它向我展示了大约 280 个套接字和管道的文件描述符

*(I have pasted the file descriptor outcome at the end of the question thread)*. 

活动 tcp 连接数为 12,但文件描述符远远超过活动连接数并且每天都在增长。

我的应用程序确实打开了 12 个文件,但文件的文件描述符计数没有增长,只有 12,这是预期的计数。 我觉得罪魁祸首是没有正确关闭的客户端套接字。

使用的示例代码

AbstractServerConnectionFactory.closeCOnnection(ClientConnId)

AbstractServerConnectionFactory connFactory = (AbstractServerConnectionFactory) applicationContext.getBean("server");
connFactory.closeConnection(clientConnId);

我从 Spring TCP 消息头中获取客户端连接 ID "IpHeaders.CONNECTION_ID"

在我的应用程序中,客户端连接到服务器套接字并发送命令,服务器套接字通过客户端建立的 TCP 连接相应地使用来自文件的数据回复命令。客户端必须每两秒向服务器套接字发送一个文本 "alive"。如果这个"alive"没有被服务器接收到,它应该 断开此客户端 connection.For 信息,我的应用程序中的 TCP 服务器套接字需要大约 3 个 tcp 客户端连接。并且如果任何客户端未能发送 "alive" 命令,则服务器套接字必须终止该连接。

我已经看到另一种关闭连接的解决方案抛出 SoftEndOfStreamException。但是这个异常似乎关闭了完整的服务器套接字。我只想关闭一个客户端连接,即无法发送 alive 命令的连接。

throw new SoftEndOfStreamException

tcp-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans=...>

    <context:property-placeholder />

    <task:annotation-driven />

    <beans:bean id="stxEtxSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer">
    </beans:bean>

    <beans:bean id="logdistSerializer" class="com.appc.logdist.tcp.socket.logdistSerializerDeSerializer">
    </beans:bean>

    <beans:bean class="com.appc.logdist.tcp.socket.listener.TcpConnCloseEventListener"></beans:bean>
    <beans:bean class="com.appc.logdist.tcp.socket.listener.TcpConnOpenEventListener"></beans:bean>
    <beans:bean class="com.appc.logdist.tcp.socket.listener.TcpConnFailedCorrEventListener"></beans:bean>
    <beans:bean class="com.appc.logdist.tcp.socket.listener.TcpConnSrvrExcepEventListener"></beans:bean>
    <beans:bean class="com.appc.logdist.tcp.socket.listener.TcpConnExcepEventListener"></beans:bean>

    <channel id="toSA"/>
    <channel id="toObAdapter" />
    <channel id="toErrorChannel" />

    <bridge input-channel="toErrorChannel" output-channel="toObAdapter"></bridge>
    <bridge input-channel="inputErrorChannel" output-channel="toObAdapter"></bridge>

<!-- Server side -->

<!-- Connection Factory -->
    <ip:tcp-connection-factory id="server"
        type="server"
        port="${port}"
        using-nio="true"
                serializer="logdistSerializer"
        deserializer="stxEtxSerializer"/>

<!-- Inbound Channel Adapter -->
    <ip:tcp-inbound-channel-adapter id="inAdapter.server"
        channel="toSA"
        connection-factory="server" />

    <beans:bean class="java.lang.String" name="hostId" >
        <beans:constructor-arg value="${hostId}"></beans:constructor-arg>
    </beans:bean>

<!-- Validation Service -->
    <service-activator input-channel="toSA"
                       ref="logdistMessageReceiver"
                       method="validate" />
                       <!-- output-channel="toObAdapter" -->
    <beans:bean id="logdistMessageReceiver"
          class="com.appc.logdist.validation.logdistInputValidator" />


<!-- Outbound Server Flow -->

<!-- Outbound Channel Adapter -->
    <ip:tcp-outbound-channel-adapter id="outAdapter.server"
        channel="toObAdapter"
        connection-factory="server" />

    <beans:bean id="logdistWaiter" class="com.appc.logdist.reader.logdistRequestServer" scope="prototype">
        <beans:property name="logdistLogRedr" ref="logdistLogReader"></beans:property>
    </beans:bean>
    <beans:bean id="logdistLogReader" class="com.appc.logdist.reader.logdistLogReaderImpl" scope="prototype"></beans:bean>

    <task:scheduled-tasks scheduler="logdistPulseScheduler">
        <task:scheduled ref="logdistMessageReceiver" method="generatePulse" fixed-delay="800" initial-delay="2"/>
        <task:scheduled ref="logdistMessageReceiver" method="checkHealthIsReceived" fixed-delay="8000" initial-delay="3"/>
    </task:scheduled-tasks>

    <task:scheduler id="logdistPulseScheduler" pool-size="6"/>

</beans:beans>

文件描述符计数

[root@logdist ~]# lsof -i -p 25871
PID    FD   TYPE             DEVICE SIZE/OFF      NODE NAME
25871  mem    REG              253,0 39470476   1457712 /Data/logdist-app/logdist-core/logdist-core.jar
25871   12u  unix 0xffff8802385b2780      0t0 100031047 socket
25871   13u  IPv4          100031049      0t0       TCP *:36152 (LISTEN)
25871   14u  IPv4          100031050      0t0       TCP *:rmiregistry (LISTEN)
25871   15u  IPv4          100031053      0t0       TCP *:46576 (LISTEN)
25871   17u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   19w   REG              253,0 43443203   1317895 /Data/logdist-app/logs/logdist-2018-08-13.2.log
25871   20u   REG              253,0  2097173   1457274 /Data/logdist-app/logdist-core/transaction-logs/part1.btm
25871   21u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   22u   REG              253,0  2097173   1457273 /Data/logdist-app/logdist-core/transaction-logs/part2.btm
25871   24u  IPv4          100031160      0t0       TCP localhost:45288->localhost:mysql (ESTABLISHED)
25871   25u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   27u  IPv4          100031429      0t0       TCP *:6866 (LISTEN)
25871   28r  FIFO                0,8      0t0 100031430 pipe
25871   29w  FIFO                0,8      0t0 100031430 pipe
25871   30u   REG                0,9        0      3853 [eventpoll]
25871   31u  IPv4          100031431      0t0       TCP *:6867 (LISTEN)
25871   32r  FIFO                0,8      0t0 100031432 pipe
25871   33w  FIFO                0,8      0t0 100031432 pipe
25871   34u   REG                0,9        0      3853 [eventpoll]
25871   35u  IPv4          100031433      0t0       TCP *:acctopus-cc (LISTEN)
25871   36r  FIFO                0,8      0t0 100031434 pipe
25871   37w  FIFO                0,8      0t0 100031434 pipe
25871   38u   REG                0,9        0      3853 [eventpoll]
25871   39u  IPv4          100031435      0t0       TCP 10.12.11.3:6866->192.102.9.50:38978 (ESTABLISHED)
25871   40u  IPv4          100931202      0t0       TCP 10.12.11.3:6867->192.102.9.50:39814 (ESTABLISHED)
25871   41u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   42u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   43u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   44r   REG              253,0   214218   1457301 /Data/logdist-app/prod-files/output/aman/2018-08-13.log
25871   45r   REG              253,0    47921   1457302 /Data/logdist-app/prod-files/output/dflow/2018-08-13.log
25871   46r  FIFO                0,8      0t0 100031446 pipe
25871   47w  FIFO                0,8      0t0 100031446 pipe
25871   48u   REG                0,9        0      3853 [eventpoll]
25871   49u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   50u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   51u  IPv4          102305722      0t0       TCP logdist:6866->192.102.65.42:43056 (ESTABLISHED)
25871   52u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   53u  IPv4          100031459      0t0       TCP 192.102.246.5:6867->192.102.246.2:55232 (ESTABLISHED)
25871   54r   REG              253,0   214218   1457301 /Data/logdist-app/prod-files/output/aman/2018-08-13.log
25871   55u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   56u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   57r  FIFO                0,8      0t0 100031465 pipe
25871   58w  FIFO                0,8      0t0 100031465 pipe
25871   59u   REG                0,9        0      3853 [eventpoll]
25871   60u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   61r  FIFO                0,8      0t0 100031466 pipe
25871   62w  FIFO                0,8      0t0 100031466 pipe
25871   63u   REG                0,9        0      3853 [eventpoll]
25871   64u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   65r  FIFO                0,8      0t0 100411961 pipe
25871   66r   REG              253,0    47921   1457302 /Data/logdist-app/prod-files/output/dflow/2018-08-13.log
25871   67r  FIFO                0,8      0t0 100171486 pipe
25871   70w  FIFO                0,8      0t0 100171486 pipe
25871   71u   REG                0,9        0      3853 [eventpoll]
25871   72w  FIFO                0,8      0t0 100411961 pipe
25871   73u   REG                0,9        0      3853 [eventpoll]
25871   74u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   75r  FIFO                0,8      0t0 100602902 pipe
25871   76w  FIFO                0,8      0t0 100602902 pipe
25871   77u   REG                0,9        0      3853 [eventpoll]
25871   78u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   79r  FIFO                0,8      0t0 100659853 pipe
25871   80w  FIFO                0,8      0t0 100659853 pipe
25871   81u   REG                0,9        0      3853 [eventpoll]
25871   82u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   83r  FIFO                0,8      0t0 100666338 pipe
25871   84w  FIFO                0,8      0t0 100666338 pipe
25871   85u   REG                0,9        0      3853 [eventpoll]
25871   86r  FIFO                0,8      0t0 100680384 pipe
25871   87r  FIFO                0,8      0t0 100674499 pipe
25871   88w  FIFO                0,8      0t0 100674499 pipe
25871   89u   REG                0,9        0      3853 [eventpoll]
25871   90w  FIFO                0,8      0t0 100680384 pipe
25871   91u   REG                0,9        0      3853 [eventpoll]
25871   92u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   93u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   94u  unix 0xffff88023adb8840      0t0 100031061 socket
25871   95r  FIFO                0,8      0t0 100680391 pipe
25871   96w  FIFO                0,8      0t0 100680391 pipe
25871   97u   REG                0,9        0      3853 [eventpoll]
25871   98r  FIFO                0,8      0t0 100680577 pipe
25871   99r  FIFO                0,8      0t0 100680392 pipe
25871  100w  FIFO                0,8      0t0 100680392 pipe
25871  101u   REG                0,9        0      3853 [eventpoll]
25871  102w  FIFO                0,8      0t0 100680577 pipe
25871  103u   REG                0,9        0      3853 [eventpoll]
25871  104u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  105u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  106r  FIFO                0,8      0t0 100680606 pipe
25871  107w  FIFO                0,8      0t0 100680606 pipe
25871  108u   REG                0,9        0      3853 [eventpoll]
25871  109u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  110r  FIFO                0,8      0t0 100680607 pipe
25871  111w  FIFO                0,8      0t0 100680607 pipe
25871  112u   REG                0,9        0      3853 [eventpoll]
25871  113r  FIFO                0,8      0t0 100680615 pipe
25871  114w  FIFO                0,8      0t0 100680615 pipe
25871  115u   REG                0,9        0      3853 [eventpoll]
25871  116u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  117u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  118r  FIFO                0,8      0t0 100680716 pipe
25871  119w  FIFO                0,8      0t0 100680716 pipe
25871  120u   REG                0,9        0      3853 [eventpoll]
25871  121u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  122u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  123u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  124r  FIFO                0,8      0t0 100680829 pipe
25871  125w  FIFO                0,8      0t0 100680829 pipe
25871  126u   REG                0,9        0      3853 [eventpoll]
25871  127u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  128r  FIFO                0,8      0t0 100680900 pipe
25871  129w  FIFO                0,8      0t0 100680900 pipe
25871  130u   REG                0,9        0      3853 [eventpoll]
25871  131u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  132r  FIFO                0,8      0t0 100681039 pipe
25871  133w  FIFO                0,8      0t0 100681039 pipe
25871  134u   REG                0,9        0      3853 [eventpoll]
25871  135r  FIFO                0,8      0t0 100681249 pipe
25871  136r  FIFO                0,8      0t0 100681141 pipe
25871  137w  FIFO                0,8      0t0 100681141 pipe
25871  138u   REG                0,9        0      3853 [eventpoll]
25871  139w  FIFO                0,8      0t0 100681249 pipe
25871  140u   REG                0,9        0      3853 [eventpoll]
25871  141u  IPv4          102309329      0t0       TCP logdist:6867->192.102.65.43:42326 (ESTABLISHED)
25871  142r  IPv4          102304207      0t0       TCP 192.102.246.5:6866->192.102.246.1:44626 (ESTABLISHED)
25871  143u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  144r  FIFO                0,8      0t0 100681458 pipe
25871  145w  FIFO                0,8      0t0 100681458 pipe
25871  146u   REG                0,9        0      3853 [eventpoll]
25871  147u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  148r  FIFO                0,8      0t0 100681463 pipe
25871  149w  FIFO                0,8      0t0 100681463 pipe
25871  150u   REG                0,9        0      3853 [eventpoll]
25871  151r  FIFO                0,8      0t0 100686734 pipe
25871  152r  FIFO                0,8      0t0 100681668 pipe
25871  153w  FIFO                0,8      0t0 100681668 pipe
25871  154u   REG                0,9        0      3853 [eventpoll]
25871  155r  FIFO                0,8      0t0 100683493 pipe
25871  156w  FIFO                0,8      0t0 100683493 pipe
25871  157u   REG                0,9        0      3853 [eventpoll]
25871  158w  FIFO                0,8      0t0 100686734 pipe
25871  159u   REG                0,9        0      3853 [eventpoll]
25871  160u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  161u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  162r  FIFO                0,8      0t0 100686738 pipe
25871  163w  FIFO                0,8      0t0 100686738 pipe
25871  164u   REG                0,9        0      3853 [eventpoll]
25871  165u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  166r  FIFO                0,8      0t0 100686840 pipe
25871  167w  FIFO                0,8      0t0 100686840 pipe
25871  168u   REG                0,9        0      3853 [eventpoll]
25871  169u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  170u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  171r  FIFO                0,8      0t0 100686935 pipe
25871  172w  FIFO                0,8      0t0 100686935 pipe
25871  173u   REG                0,9        0      3853 [eventpoll]
25871  174u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  175r  FIFO                0,8      0t0 100686952 pipe
25871  176w  FIFO                0,8      0t0 100686952 pipe
25871  177u   REG                0,9        0      3853 [eventpoll]
25871  178r  FIFO                0,8      0t0 100687163 pipe
25871  179r  FIFO                0,8      0t0 100687079 pipe
25871  180w  FIFO                0,8      0t0 100687079 pipe
25871  181u   REG                0,9        0      3853 [eventpoll]
25871  182w  FIFO                0,8      0t0 100687163 pipe
25871  183u   REG                0,9        0      3853 [eventpoll]
25871  184u   REG              253,0    47921   1457302 /Data/logdist-app/prod-files/output/dflow/2018-08-13.log
25871  185r   REG              253,0   214218   1457301 /Data/logdist-app/prod-files/output/aman/2018-08-13.log
25871  186r  FIFO                0,8      0t0 101182477 pipe
25871  187r  FIFO                0,8      0t0 101071687 pipe
25871  188w  FIFO                0,8      0t0 101071687 pipe
25871  189u   REG                0,9        0      3853 [eventpoll]
25871  190w  FIFO                0,8      0t0 101182477 pipe
25871  191u   REG                0,9        0      3853 [eventpoll]
25871  192u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  193u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  194u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  195u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  196u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  197r  FIFO                0,8      0t0 101182689 pipe
25871  198w  FIFO                0,8      0t0 101182689 pipe
25871  199u   REG                0,9        0      3853 [eventpoll]
25871  200r  FIFO                0,8      0t0 101194033 pipe
25871  201r  FIFO                0,8      0t0 101182736 pipe
25871  202w  FIFO                0,8      0t0 101182736 pipe
25871  203u   REG                0,9        0      3853 [eventpoll]
25871  204r  FIFO                0,8      0t0 101183098 pipe
25871  205w  FIFO                0,8      0t0 101183098 pipe
25871  206u   REG                0,9        0      3853 [eventpoll]
25871  207r  FIFO                0,8      0t0 101183099 pipe
25871  208w  FIFO                0,8      0t0 101183099 pipe
25871  209u   REG                0,9        0      3853 [eventpoll]
25871  210w  FIFO                0,8      0t0 101194033 pipe
25871  211u   REG                0,9        0      3853 [eventpoll]
25871  212u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  213u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  214r  FIFO                0,8      0t0 101194037 pipe
25871  215w  FIFO                0,8      0t0 101194037 pipe
25871  216u   REG                0,9        0      3853 [eventpoll]
25871  217u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  218u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  219r  FIFO                0,8      0t0 101194041 pipe
25871  220w  FIFO                0,8      0t0 101194041 pipe
25871  221u   REG                0,9        0      3853 [eventpoll]
25871  222u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  223u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  224r  FIFO                0,8      0t0 101194254 pipe
25871  225w  FIFO                0,8      0t0 101194254 pipe
25871  226u   REG                0,9        0      3853 [eventpoll]
25871  227r  unix 0xffff88023adb8840      0t0 100031061 socket
25871  228r  FIFO                0,8      0t0 101194255 pipe
25871  229w  FIFO                0,8      0t0 101194255 pipe
25871  230u   REG                0,9        0      3853 [eventpoll]
25871  231r  FIFO                0,8      0t0 101194356 pipe
25871  232w  FIFO                0,8      0t0 101194356 pipe
25871  233u   REG                0,9        0      3853 [eventpoll]
25871  234u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  235u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  236r  FIFO                0,8      0t0 101194403 pipe
25871  237w  FIFO                0,8      0t0 101194403 pipe
25871  238u   REG                0,9        0      3853 [eventpoll]
25871  239u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  240r  FIFO                0,8      0t0 101194469 pipe
25871  241w  FIFO                0,8      0t0 101194469 pipe
25871  242u   REG                0,9        0      3853 [eventpoll]
25871  243u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  244r  FIFO                0,8      0t0 101194676 pipe
25871  245w  FIFO                0,8      0t0 101194676 pipe
25871  246u   REG                0,9        0      3853 [eventpoll]
25871  247u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  248r  FIFO                0,8      0t0 101194827 pipe
25871  249w  FIFO                0,8      0t0 101194827 pipe
25871  250u   REG                0,9        0      3853 [eventpoll]
25871  251u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  252r  FIFO                0,8      0t0 101194887 pipe
25871  253w  FIFO                0,8      0t0 101194887 pipe
25871  254u   REG                0,9        0      3853 [eventpoll]
25871  255u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  256r  FIFO                0,8      0t0 101195094 pipe
25871  257w  FIFO                0,8      0t0 101195094 pipe
25871  258u   REG                0,9        0      3853 [eventpoll]
25871  259u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  260r  FIFO                0,8      0t0 101195196 pipe
25871  261w  FIFO                0,8      0t0 101195196 pipe
25871  262u   REG                0,9        0      3853 [eventpoll]
25871  263u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  264r  FIFO                0,8      0t0 101195304 pipe
25871  265w  FIFO                0,8      0t0 101195304 pipe
25871  266u   REG                0,9        0      3853 [eventpoll]
25871  267r  FIFO                0,8      0t0 101238507 pipe
25871  268w  FIFO                0,8      0t0 101238507 pipe
25871  269u   REG                0,9        0      3853 [eventpoll]
25871  270u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  271r  FIFO                0,8      0t0 101279569 pipe
25871  272w  FIFO                0,8      0t0 101279569 pipe
25871  273u   REG                0,9        0      3853 [eventpoll]
25871  274r  FIFO                0,8      0t0 101731766 pipe
25871  275r  FIFO                0,8      0t0 101313450 pipe
25871  276w  FIFO                0,8      0t0 101313450 pipe
25871  277u   REG                0,9        0      3853 [eventpoll]
25871  278w  FIFO                0,8      0t0 101731766 pipe
25871  279u   REG                0,9        0      3853 [eventpoll]
25871  280u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  281u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  282u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  283r  FIFO                0,8      0t0 101731773 pipe
25871  284w  FIFO                0,8      0t0 101731773 pipe
25871  285u   REG                0,9        0      3853 [eventpoll]
25871  286u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  287r  FIFO                0,8      0t0 101731774 pipe
25871  288w  FIFO                0,8      0t0 101731774 pipe
25871  289u   REG                0,9        0      3853 [eventpoll]
25871  290u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  291r  FIFO                0,8      0t0 101731983 pipe
25871  292w  FIFO                0,8      0t0 101731983 pipe
25871  293u   REG                0,9        0      3853 [eventpoll]
25871  294r  unix 0xffff88023adb8840      0t0 100031061 socket
25871  295r  FIFO                0,8      0t0 101731984 pipe
25871  296w  FIFO                0,8      0t0 101731984 pipe
25871  297u   REG                0,9        0      3853 [eventpoll]
25871  298u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  299r  FIFO                0,8      0t0 101732085 pipe
25871  300w  FIFO                0,8      0t0 101732085 pipe
25871  301u   REG                0,9        0      3853 [eventpoll]
25871  302r  FIFO                0,8      0t0 102106556 pipe
25871  303r  FIFO                0,8      0t0 101732194 pipe
25871  304w  FIFO                0,8      0t0 101732194 pipe
25871  305u   REG                0,9        0      3853 [eventpoll]
25871  306u  FIFO                0,8      0t0 102106556 pipe
25871  307u  IPv4          102266066      0t0       TCP logdist:rmiregistry->192.102.65.18:50904 (ESTABLISHED)
25871  309u   REG                0,9        0      3853 [eventpoll]
25871  310u  IPv4          102037167      0t0       TCP logdist:rmiregistry->192.102.65.18:51359 (ESTABLISHED)
25871  311u  unix 0xffff88023ad64f00      0t0 102039331 /tmp/.java_pid25871.tmp
25871  313w   REG              253,0    17068   1317908 /root/.yjp/log/logdist-core-25871.log
25871  314r   REG              253,0  1298105   1048616 /tmp/yjp201807311816.jar
25871  315u  IPv4          102039343      0t0       TCP localhost:scp-config (LISTEN)
25871  316u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  317u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  318r  FIFO                0,8      0t0 102106560 pipe
25871  319w  FIFO                0,8      0t0 102106560 pipe
25871  320u   REG                0,9        0      3853 [eventpoll]
25871  321u  IPv4          102106561      0t0       TCP 10.12.11.3:acctopus-cc->192.102.9.52:36330 (ESTABLISHED)
25871  322r   REG              253,0 79421704   1457300 /Data/logdist-app/prod-files/output/sfpl/2018-08-13.log
25871  323u  unix 0xffff88023adb8840      0t0 100031061 socket
25871  324r  FIFO                0,8      0t0 102106779 pipe
25871  325w  FIFO                0,8      0t0 102106779 pipe
25871  326u   REG                0,9        0      3853 [eventpoll]
25871  327u  IPv4          102115534      0t0       TCP 192.102.246.5:acctopus-cc->192.102.246.2:32994 (ESTABLISHED)
25871  328r  FIFO                0,8      0t0 102106861 pipe
25871  329w  FIFO                0,8      0t0 102106861 pipe
25871  330u   REG                0,9        0      3853 [eventpoll]
25871  331r  FIFO                0,8      0t0 102107226 pipe
25871  332w  FIFO                0,8      0t0 102107226 pipe
25871  333u   REG                0,9        0      3853 [eventpoll]
25871  334r  FIFO                0,8      0t0 102115327 pipe
25871  335w  FIFO                0,8      0t0 102115327 pipe
25871  336u   REG                0,9        0      3853 [eventpoll]
25871  337u  IPv4          102115328      0t0       TCP logdist:acctopus-cc->192.102.65.43:36846 (ESTABLISHED)
25871  338r   REG              253,0 79421704   1457300 /Data/logdist-app/prod-files/output/sfpl/2018-08-13.log
25871  339r  FIFO                0,8      0t0 102115331 pipe
25871  340w  FIFO                0,8      0t0 102115331 pipe
25871  341u   REG                0,9        0      3853 [eventpoll]
25871  342r   REG              253,0 79421704   1457300 /Data/logdist-app/prod-files/output/sfpl/2018-08-13.log
25871  343r  FIFO                0,8      0t0 102115537 pipe
25871  344w  FIFO                0,8      0t0 102115537 pipe
25871  345u   REG                0,9        0      3853 [eventpoll]
25871  346u  IPv4          102276973      0t0       TCP logdist:rmiregistry->192.102.65.18:54587 (ESTABLISHED)

使用它的 ID 关闭套接字应该完全关闭它。

但是,只需设置soTimeout 属性,操作系统将通知框架,如果在此期间没有收到数据,框架将关闭套接字。

throw new SoftEndOfStreamException

我不确定你在哪里做的,但我想不出它会关闭服务器套接字的场景。

该异常只能从反序列化器中抛出(当它检测到消息之间的套接字关闭时)。