How do I kill a URLConnection?

I've been working on a program that requires the opening of a URL connection. The program works great until I run into a link that hangs. The connection sits open and waits for a server response, slowing the program down significantly. Anyone have any suggestions on how I could kill the connection after say...10 seconds?

URL resource = resourceURI.toURL();
URLConnection con = resource.openConnection();
try
{
resourceStream = con.getInputStream();
thisNode.setBroken(false);
} catch(IOException e) {
thisNode.setBroken(true);
}

Comments

  • : I've been working on a program that requires the opening of a URL connection. The program works great until I run into a link that hangs. The connection sits open and waits for a server response, slowing the program down significantly. Anyone have any suggestions on how I could kill the connection after say...10 seconds?
    :
    : URL resource = resourceURI.toURL();
    : URLConnection con = resource.openConnection();
    : try
    : {
    : resourceStream = con.getInputStream();
    : thisNode.setBroken(false);
    : } catch(IOException e) {
    : thisNode.setBroken(true);
    : }
    :

    If you are using jdk 1.4, try this
    [code]
    System.setProperty( "sun.net.client.defaultConnectTimeout", "10000");
    System.setProperty( "sun.net.client.defaultReadTimeout", "10000" );
    [/code]

    look at http://java.sun.com/j2se/1.4/docs/guide/net/properties.html


  • Thank you so much.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories