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.
You've two choices when checking something... polling or catching events.
Since the webserver isn't going to send you an event to say it's changed, you've gone the only route possible. Check it yourself at periodic intervals.
Checking the timestamp is the quickest, which means you do not have to parse the URL.
If you want accuracy, to ensure the file has changed, even if the timestamp has not, you'd need to generate
a checksum on the URL stream contents.
But, I can't see any significant improvement on what you done...
Are you just fishing for complements !
The HTTP protocol allows for a conditional GET, which will retrieve the file only if it's newer than a certain timestamp. Using that, you won't have to download the entire page each time you poll the server.