简体   繁体   English

套接字读取超时时java lib如何处理接收到的数据?

[英]How does java lib deal with the received data when socket read timeout?

If a socket reads timeout(connection not closed) and later os receives the data, how does the java lib deal with the data?如果套接字读取超时(连接未关闭)并且后来 os 接收到数据,java lib 如何处理数据?

Eg.Two tcp connections/sockets are in the connection pool.例如,连接池中有两个 tcp 连接/套接字。 One thread reads timeout and return(release the connection to the connection pool) and then another thead uses the same connection;一个线程读取超时并返回(释放连接到连接池),然后另一个线程使用相同的连接; then another thead maybe receives the response data of the first thread.那么另一个 thead 可能会收到第一个线程的响应数据。 I think it's not right.我认为这是不对的。 How does java lib(eg.httpclint) prevent another thread from receiving the response data of the previous thread's request when two threads use the same connection in turn?当两个线程轮流使用同一个连接时,java lib(eg.httpclint)如何防止另一个线程接收到前一个线程请求的响应数据?

Thx!谢谢!

It depends on what kind of data you are receiving here.这取决于您在此处接收的数据类型。 If it is strictly based on which thread will handle the received data, then you need to make sure the data is identified using some kind of a GUID and Thread ID combination so that the sender and receiver know that the message has been consumed or lost.如果严格基于哪个线程将处理接收到的数据,那么您需要确保使用某种 GUID 和线程 ID 组合来标识数据,以便发送方和接收方知道消息已被消耗或丢失。 Ideally, you should not have a situation where your logic is dependent on the underlying threads unless that logic is OS-layer specific.理想情况下,您的逻辑不应该依赖于底层线程,除非该逻辑是特定于操作系统层的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM