aspose file tools*
The moose likes Servlets and the fly likes InterruptedIOException: Read timed out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "InterruptedIOException: Read timed out" Watch "InterruptedIOException: Read timed out" New topic
Author

InterruptedIOException: Read timed out

Rama Raghavan
Ranch Hand

Joined: Aug 22, 2001
Posts: 116
I have a client that opens a URL connection to a servlet and sends data in post stream. The client uses writeObject to serialize an object into the post stream. Client invokes the servlet over and over again, for 2000 records of data, sequentially.
Looks like the servlet fails at random when reading data from the post stream.
Servlet failed with Exception
java.io.InterruptedIOException: Read timed out
at java.net.SocketInputStream.socketRead(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:86)
Any help is appreciated..


Rama Raghavan<br />SCJP2<br />SCWCD
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
To be honest with you Rama, I dun have an answer to your Q. so what am i doin here? I am here to suggest alternatives.
1) Try to set the sessions setMaxInactiveInterval() to a longiiish value
2) Use BufferedInpuStream instead of the regular/pushback input stream that u get with the URL Connection Object and then try to mark the read data after some interval and after u catch the InterruptedIOException , start reading from the mark again.
I know that this will definaely get u all the data that u want, but i am not sure how i am helping u with performance.
S


Adios
adam oczos
Greenhorn

Joined: May 12, 2003
Posts: 17
hello;
anybody figured out how to resolve that problem? i'm also reading data using BufferedReader and getReader() method, but still can't get rid of "Read timed out" message.
any place where I can set this parameter up?
thanx.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
.adam,
Please change your name to be compliant with JavaRanch's naming policy. It should not be obviously fictitious.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy


"JavaRanch, where the deer and the Certified play" - David O'Meara
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Could you clarify what this means:
Client invokes the servlet over and over again, for 2000 records of data, sequentially.

Do you really mean 2000 separate connections? Or is it 2000 objects being sent in a single connection?
I just noticed that you say "writeObject" and also "getReader" - surely you are not trying to read an object stream (binary data) with a Reader which expects character data and will try to turn the binary data into characters.
Bill
adam oczos
Greenhorn

Joined: May 12, 2003
Posts: 17
i hope right now my nick is much better.
going back to the topic.
in my case i use getReader() to read characters from HTTP body included in POST (using BufferedReader).
no idea why in case of relatively big files it ends up with READ TIMED OUT. ok... connection might be broken, bo why there's no place to set the timeout up?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
But you said the client uses writeObject - thats binary data. If you client is using an ObjectOutputStream to write objects, you MUST use a binary input stream to create an ObjectInputStream.
--
I don't think your problem is related to the server's timeout setting, instead, I suspect there is something wrong with the way you are trying to read the stream from the client.
Have you ever suceeded in reading a single object this way?
Bill
adam oczos
Greenhorn

Joined: May 12, 2003
Posts: 17
just to clarify the issue...
the original problem was not posted by me (please have a look above). i just noticed that i have a very similar problem (reading data from POST stream), so i attached myself there :-)
in my case it's not a bit stream but characters (in fact pure XML). that's why i use getReader() to catch data.
i believe TIME OUT may come from both: either getReader or getInputStream. i just couldn't find a proper solution for that.
anyway - thanx a lot.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Whoops - sorry - I didn't notice the ancient date on the first post - just got as far as "May".
How much XML are you actually writing? Are we talking megabytes or what? With Tomcat there is a connectionTimeout in the server.xml definition for a connector. Mine currently says
connectionTimeout="60000" which I assume is milliseconds.
Bill
adam oczos
Greenhorn

Joined: May 12, 2003
Posts: 17
thanx again for the reply.
in fact the biggest file sent was around 0.5 MB, but we can assume that the max size is 1 MB.
the problem here is that's not Tomcat, but OC4J (Oracle Container for Java). i did my best to find time_out parameter there. and i found nothing...
my question is: is it really container-related or maybe an internal parameter hardcoded somewhere deep inside the getReader/getInputStream definition? i wish i could touch it.
regards;
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Another possibility just occurred to me after seeing a similar problem on comp.lang.java.programmer. How is the server side supposed to determine that the stream of data is finished? Are you sure the transmitting side closes the stream?
Maybe the server is waiting for data that never comes?
Bill
adam oczos
Greenhorn

Joined: May 12, 2003
Posts: 17
good questions... i need to check if the stream is really closed after data is sent.
hmmm... what if i count bytes incoming and compare them with getContentLength() value?
no. the most common case is that xml is incomplete when time out occures. that means the stream is broken in the middle.
anyway... thnx for taking care of that :-) looks like it's much more complex, than i thought.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
A possible cause for that broken XML text would be that the sending application has not done a flush() so there are still characters in the buffer. All close() methods do a flush() first of course.
I wasted hours on this when first getting into servlet-applet communication.
Bill
adam oczos
Greenhorn

Joined: May 12, 2003
Posts: 17
i wish the client was written in Java, but it's not.
anyway - i DO appreciate your help. thanx again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: InterruptedIOException: Read timed out