java.net.SocketTimeoutException:读取超时 [英] java.net.SocketTimeoutException: Read timed out

查看:20395
本文介绍了java.net.SocketTimeoutException:读取超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端服务器架构的应用程序。客户端
使用带有Java Swing / AWT的Java Web Start,而sert使用带有
Tomcat的HTTP服务器/ Servlet。
通过对象的序列化进行通信,创建
ObjectOutput序列化一个字节数组并分别发送到服务器
,称为ObjectInputStream并反序列化。

I have an application with client server architecture. The client use Java Web Start with Java Swing / AWT and the sert uses HTTP server / Servlet with Tomcat. The communication is made from the serialization of objects, create a ObjectOutput serializes a byte array and send to the server respectively called the ObjectInputStream and deserializes.

应用程序跟随正确通信到某个
并发时间,开始显示错误
SocketException read timeout。当服务器在我的servlet doPost方法中调用方法
ObjectInputStream.getObject()时,会发生错误。

The application follows communicating correctly to a certain time of concurrency where starting to show error "SocketException read timeout". The erro happens when the server invoke the method ObjectInputStream.getObject() in my servlet doPost method.

tomcat会变慢并且错误开始减少服务器响应时间,直到我必须重新启动服务器并且一切正常后的崩溃时间。

The tomcat will come slow and the errors start to decrease server response time until the crash time where i must restart the server and after everything works.

有人遇到过这个问题吗?

Someone went through this problem ?

客户代码

URLConnection conn =  url.openConnection();
conn.setDoOutput(true);

OutputStream os = conn.getOutputStream();
ObjectOutputStream oss = new ObjectOutputStream(os);

oss.writeUTF("protocol header sample");

oss.writeObject(_parameters);
oss.flush();
oss.close();

服务器代码

ObjectInputStream input = new ObjectInputStream(_request.getInputStream());
String method = input.readUTF();

parameters = input.readObject();

input.readObject()是错误的地方

input.readObject() is where the error is

推荐答案

您还没有给我们提供太多信息,尤其是关于客户端的信息。但我怀疑客户端是:

You haven't given us much information to go on, especially about the client side. But my suspicion is that the client side is:


  • 未能设置Content-length标头(或将其设置为错误的值),

  • 无法刷新输出流,和/或

  • 没有关闭套接字的输出端。

神秘。

根据您更新的问题,它看起来很像像上面没有一样。以下是其他几种可能性:

Based on your updated question, it looks like none of the above. Here are a couple of other possibilities:


  • 由于某种原因,客户端要么在序列化期间完全锁定,要么花费很长时间。

  • 客户端和服务器之间存在导致问题的代理。

  • 您遇到与负载相关的网络问题或网络硬件问题。

另一种可能的解释是你有内存泄漏,而且减速是由于内存耗尽,GC会占用越来越多的时间。如果已启用它们,它将显示在GC日志中。

Another possible explanation is that you have a memory leak, and that the slowdown is caused by the GC taking more and more time as you run out of memory. This will show up in the GC logs if you have them enabled.

这篇关于java.net.SocketTimeoutException:读取超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆