smartly handle "java.net.connectException: connection timed out" error?
Hi, I have written a program to periodly check a web site to read some information periodly (use Timer). The code is posted below.
The problem is: when the "connection timed out" exception happens, the program seems stopped to execute at next desired time (after 10min) but did not quit either... (There was two "connection timed out" error)
Can you tell me what happended there and how should I correct the code make it handle this network exception more smartly? I don't want to code to quit, I want it just ignore the error (since sometimes network is not stable) and continually run at next desired time...
Thanks for your attention!
Mike
publicvoid readHTML(){
try{
URL url =new URL("http://www.cnn.com");
BufferedReader in =new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) !=null){
//process str.....
//if wanted info is read, process it and return
return;
}
}
}catch (MalformedURLException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
}
publicvoid monitor(){
Timer timer =new Timer();
timer.schedule(new RemindTask(), 0, interval*1000);
}
class RemindTaskextends TimerTask{
publicvoid run(){
readHTML();
}
}

