简体   繁体   中英

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?

Eg.Two tcp connections/sockets are in the connection pool. 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. 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?

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. Ideally, you should not have a situation where your logic is dependent on the underlying threads unless that logic is OS-layer specific.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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