Re: Socket with setSoTimeout() never times out



On Feb 28, 2:14 pm, Gordon Beaton <n....@xxxxxxxxx> wrote:
On Thu, 28 Feb 2008 09:45:37 -0800 (PST), phillip.s.pow...@xxxxxxxxx wrote:
I have a Socket class instance that I need to time out after a
specific amount of time:

It isn't at all clear what you're trying to do. You create a Socket
and a BufferedReader, but immediately close the BufferedReader which
closes the Socket too (so there's no need for shutdown{In/Out}put).

I should have tried to make myself more clear. MailAdminReader is a
class that will connect to a remote mail server and retrieve someone's
mail. I am not allowed to update nor change anything in
MailAdminReader so I can do nothing about the fact that the class has
no ability to handle timeouts. If the remote mail server is not
available, MailAdminReader method checkUserMail() will keep trying for
minutes on end ad infinitum. What I am trying to do is to prevent
that from happening by figuring out a way to limit the time
checkUserMail() has to check remote mail while having no ability to
change MailAdminReader to do so.

Does that make more sense now?



Further you can't set a property on one Socket instance and expect it
to have any effect on another one used by your mailAdminReader,
regardless of what you connect to. In case that's what you're hoping.

If you can't fix this in the mailAdminReader class itself, make the
call in a separate thread, and wait at most 5 seconds for the thread
to finish.

How would I do this within a JSP script?


Or if you simply want to introduce a 5s delay in your code, try
Thread.sleep().

/gordon

--

.