java timeout超时不抛异常,java.net.SocketTimeoutException:读取超时

在Java WebStart与Tomcat应用的客户端-服务器架构中,遇到并发时出现'SocketException read timeout'错误。错误发生在服务器的Servlet doPost方法调用ObjectInputStream getObject()时。随着错误发生,Tomcat响应速度减慢,最终导致服务器崩溃。解决方案可能涉及客户端设置Content-length头、刷新输出流或关闭套接字,也可能与代理、网络问题或内存泄漏有关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

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.

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 ?

Client Code

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();

Server Code

ObjectInputStream input = new ObjectInputStream(_request.getInputStream());

String method = input.readUTF();

parameters = 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:

failing to setting the Content-length header (or setting it to the wrong value),

failing to flush the output stream, and/or

not closing the output side of the socket.

Mysterious.

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

For some reason the client side is either locking up entirely during serialization or taking a VERY LONG TIME.

There is a proxy between the client and server that is causing problems.

You are experiencing load-related network problems, or network hardware problems.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值