Re: timout on line of code

From: Knute Johnson (nospam_at_sagebrush.frazmtn.com)
Date: 12/19/04


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/


Relevant Pages

  • Re: Washing machine schematic, OT.
    ... How could the connections become incorrect? ... position lug on the new timer box. ... timer replacement. ... roo cullers, ...
    (rec.audio.tubes)
  • Re: [bug] stuck localhost TCP connections, v2.6.26-rc3+
    ... part of the handshake is received, but the socket ... isn't put on the accept queue until a real data packet arrives. ... I did run tests where the server died in between the handshake being ... can display apparently large timer values when the timer is elapsed ...
    (Linux-Kernel)
  • Re: timer and threading help needed
    ... running and you could tie your timer to that easily, ... My original C# app tuned a receiver over an RS232 port and the receiver ... buffer out over another socket back to the client. ... I have been unable to run my C# app on a win2003 server. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: heavy duty timer for Espresso machine?? mine burned out
    ... a few digital programmable timers from Lowe's, Home Depot or ... Problem with this timer besides sort of working ... Are the digitals dying or just failing to power the Andreja? ... If they are dying, check the wall socket. ...
    (alt.coffee)
  • Re: Why wont TTimer event trigger (on Formless project)??
    ... > This definitely shouldn't be the case if you use GetMessage. ... Put the timer ... What I am finding is that creating a Socket component on the fly, ... doesn't appear to acknowledge any incoming connection (or commands)!? ...
    (comp.lang.pascal.delphi.misc)