Java Linux Nonblocking Socket Timeout Behavior

夙愿已清 提交于 2019-12-05 12:16:01

The issue is dealing with Linux and not my code. When I run the exact same setup on a Windows box (on the same hardware) it never times out, but after several hours they start to occur on Linux. It must be some kind of TCP setting in Linux that's causing it to happen. Thanks for the suggestion.

The -doCloseWithReadPending option in Java and JRE versions 1.5 or 5.0 allows one thread to close a socket when there is a read pending on the same socket from another thread.

When close() is called on a socket which has an outstanding read call from another thread, the close() by default blocks the socket until the read call completes.

With the -doCloseWithReadPending option, the socket close() call closes the socket and in the context of the thread with the pending read, a SocketException with the message "Socket closed" is thrown.

I don't know if this is the root cause of your issue without seeing the code, but I thought I would add this here incase it affects your issue.

So in both the case that works (Windows with recent JVM) and the case that doesn't (Linux with recent JVM), both the server and client are on the same machine in the same JVM?

Can you clarify what "all of the sudden gradually" means? Like, after a few hours -- and always the same number of hours -- then within a few seconds all server-side sockets throw exceptions?

You don't mention the client thread reading the data that comes back. Perhaps it's stopped and you haven't noticed. (What is the client thread doing when the server thread encounters the 500 rapid exceptions? Try a few stack dumps in succession to see.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!