Re: timout on line of code
From: Knute Johnson (nospam_at_sagebrush.frazmtn.com)
Date: 12/19/04
- Next message: Andy: "Re: Classes in jar can't load - why?"
- Previous message: Rico: "Re: JSP, session, 'caching'"
- In reply to: Ike: "Re: timout on line of code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 19 Dec 2004 11:05:57 -0800
Ike wrote:
> Knute,
>
> Can you think of a way in Java such that, using a timer, it works almost as
> a "goto" statement if it times out? -Ike
>
> "Knute Johnson" <nospam@sagebrush.frazmtn.com> wrote in message
> news:1103431775.3bc53ad4ac9fac2df7aeb0c421a763b5@1usenet...
>
>>Ike wrote:
>>
>>
>>>>Just what would make that line of code hang?
>>>>
>>>>--
>>>>
>>>>Knute Johnson
>>>>email s/nospam/knute/
>>>
>>>
>>>A google search reveals numerous times others have, in the past, had
>>>inexplicable, eternal hanging on:
>>>
>>>URLConnection.getInputStream();
>>>
>>>
>>>
>>>Under all different JVMs. Has anyone ever figured out the resolution to
>>>this? We havent changed anything, just, suddenly, faced with eternal
>
> hanging
>
>>>on this particular line. -Ike
>>>
>>>
>>>
>>
>>1.5 has a setReadTimeout() that will throw a SocketTimeoutException if
>>the read timeout is exceeded. If you can't use 1.5, you could use an
>>alligator but it would have to close your program. There was a similar
>>problem with a feature of JavaSound before 1.5 came out and it could
>>hang. Use a Timer to call System.exit() if it waits too long.
>>
>>--
>>
>>Knute Johnson
>>email s/nospam/knute/
>
>
>
Here's the problem. If you can't use 1.5 and get your call to throw an
exception you can't bypass the hung instruction. You can use a timer
but it is running in a different thread so you can't interrupt the
thread with the hung instruction. Calling System.exit() works however
undesirable that is. You could try using some other form of socket to
connect instead of URLConnection and then closing the socket will cause
an exception to be thrown.
My only other suggestion is to change the architecture of your program
and create a connection manager that spawns the connections and if they
don't report back in time, create another one. That should be
satisfactory if only a small percentage of your connections actually hang.
-- Knute Johnson email s/nospam/knute/
- Next message: Andy: "Re: Classes in jar can't load - why?"
- Previous message: Rico: "Re: JSP, session, 'caching'"
- In reply to: Ike: "Re: timout on line of code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|