Monitoring a URL!
Hey Guys
How would you go about constantly and effeciently monitoring a url?
Currently, I am doing it in the most logical and simple way that came to me.
I have a timer that wakes up every second, makes a connection to a url using the URL and URLConnection class, checks the lastModified time for the file (index.html) in my case. If the
current timestamp is different than the previous one, I know the file has been altered.
I am curious to find out if there exists a better (in terms of efficiency) way to monitor a url.
Any thoughts?
:cheers
vic
private class PageLoader extends TimerTask {
BufferedReader data;
String url = "23.87.345.234/index.html";
public PageLoader(){}
public void run() {
try {
String line;
url = new URL(string);
uconn = url.openConnection();
long newtimestamp = uconn.getLastModified();
if(newtimestamp > oldtimestamp){
oldtimestamp = newtimestamp;
BufferedReader data = new BufferedReader(new InputStreamReader(url.openStream()) );
StringBuffer buf = new StringBuffer();
while ( ( line = data.readLine() ) != null ) {
buf.append( line + "\n" );
}
System.out.println(buf.toString());
data.close();
}else{
System.err.println("Nothing has changed.");
}
Thread.sleep(1000);
}catch( Exception ioe ){
ioe.getMessage();
}
}
}

