4

我有一个 Java 非阻塞服务器,它跟踪选择器中的所有套接字通道。然后我与服务器建立 500 个连接并定期发送数据。服务器接收到的每条数据都会回显给客户端。

问题出现在测试工作出色的几个小时,然后突然间,服务器管理的所有套接字在尝试读取数据时都会抛出 Connection timed out IOException。

我已经查看了客户端线程是否被饿死(而不是发送数据),但我正在让客户端线程遍历所有套接字并写出数据。流量似乎一直在正常流动,但一段时间后它就全部消失了。任何想法可能导致这种行为?

我正在使用最新版本的 Java 6 的 Linux 平台上运行。我的应用程序启动两个线程,一个用于服务器,一个用于所有客户端。提前致谢!

额外: 问题是处理 Linux 而不是我的代码。当我在 Windows 机器上(在同一硬件上)运行完全相同的设置时,它永远不会超时,但几个小时后它们开始在 Linux 上发生。一定是Linux中的某种TCP设置导致它发生。谢谢你的建议。

4

3 回答 3

1

问题是处理 Linux 而不是我的代码。当我在 Windows 机器上(在同一硬件上)运行完全相同的设置时,它永远不会超时,但几个小时后它们开始在 Linux 上发生。一定是Linux中的某种TCP设置导致它发生。谢谢你的建议。

于 2009-06-26T14:20:43.110 回答
0

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.

于 2009-06-22T20:31:55.067 回答
0

因此,在两种情况下(Windows 和最新的 JVM)和不工作的情况(Linux 和最新的 JVM),服务器和客户端都在同一个 JVM 中的同一台机器上?

你能澄清一下“突然逐渐”是什么意思吗?就像,几个小时后——而且总是相同的小时数——然后在几秒钟内所有服务器端套接字都会抛出异常?

您没有提到客户端线程读取返回的数据。也许它已经停止了,而你没有注意到。(服务端线程遇到500个快速异常时,客户端线程在做什么?连续尝试几次堆栈转储看看。)

于 2009-07-03T21:00:42.073 回答