Howdy, Stranger!

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

Categories

How do I kill a URLConnection?

extaticextatic Member Posts: 13
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

  • NazgulNazgul Member Posts: 63
    : 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


  • extaticextatic Member Posts: 13
    Thank you so much.

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ______ // http://forcoder.org // free video tutorials and ebooks about < R Python JavaScript C PHP C# MATLAB Objective-C Ruby Delphi Go Assembly Scratch C++ Swift Visual Basic Visual Basic .NET PL/SQL Java Perl VBScript Lisp Scheme SAS Bash Transact-SQL Scala Ada Logo Fortran Apex FoxPro Dart Erlang ML Awk Prolog Lua Julia D ABAP F# Crystal Clojure Rust Alice Kotlin Hack COBOL LabVIEW /> ____

Sign In or Register to comment.