How to interupt Blocking IO
I have a problem where I access a web service via a vendor api and I guess because of the vendor's firewall/load balancer, sometimes the connections are disconnected in the read operation. Since the read is a blocking operation it never returns. I have had connections open for up to as many as five days.
Does anyone have any clues as to how I can prevent this? Will having the vendor expose the java.net.URLConnection.setReadTimeout() prevent the connection from staying open so long? If I can write a class to interupt the thread that is blocking will that stop the blocking read?
TIA
Mike
[618 byte] By [
madd_mikea] at [2007-11-26 13:11:18]

# 1
> I have a problem where I access a web service via a
> vendor api and I guess because of the vendor's
> firewall/load balancer, sometimes the connections are
> disconnected in the read operation. Since the read
> is a blocking operation it never returns. I have had
> connections open for up to as many as five days.
>
> Does anyone have any clues as to how I can prevent
> this?
Solutions
1. Modify the firewall
2. Don't hold connections open idenfinitely
3. Send something on the socket - read is not sufficient.
For the last one if you are using a connection pool there is often a mechanism for doing this.
> Will having the vendor expose the
> java.net.URLConnection.setReadTimeout() prevent the
> connection from staying open so long? If I can write
> a class to interupt the thread that is blocking will
> that stop the blocking read?
The firewall monitors the traffic on the connection. Nothing you do outside of traffic will stop that from happening.
Naturally if you don't keep a connection open longer than the timeout period then the firewall won't terminate it.