On 4/6/06, Derrick Oswald <Der...@ro...> wrote:
>
> You might want to set the connect timeout in your mainline:
> System.setProperty ("sun.net.client.defaultReadTimeout", "7000");
> System.setProperty ("sun.net.client.defaultConnectTimeout", "7000=
");
>
Hello,
I don't know the reason but it completly doesn't work for me - I
checked http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html
so this property is checked for 1.5, but partial code below still
freezes for some URLs which don't respond.
System.setProperty ("sun.net.client.defaultReadTimeout", "1500");
System.setProperty ("sun.net.client.defaultConnectTimeout", "1500");
String page =3D"", line =3D "";
try {
=09URL url =3D new URL("http://www.i-am-bad-url-and-dont-respond.com/");
=09/*URLConnection urlconn =3D url.openConnection();
=09InputStream in =3D urlconn.getInputStream();*/
=09InputStream in =3D url.openStream();
=09Reader r =3D new InputStreamReader(in);
=09BufferedReader br =3D new BufferedReader(r);
=09while((line=3Dbr.readLine())!=3Dnull){
=09=09page +=3D line;
=09}
} catch (MalformedURLException e) {
=09System.out.println(e.getMessage());
} catch (IOException e) {
=09System.out.println(e.getMessage());
}
//it will never gets here
It's piece of code to test properties but I have exactly same
situation with HTMLParser, and don't know where is the problem.
Sorry, to ask again same question but it's really frustrating for me
not to have simple timeout for connection :( If anyone have other
hint/clue for this pls answer me.
Best regards,
Adr
|