I have a program to read some RSS feeds, parse them, and copy the links somewhere else. Well! I want to check the RSS feeds about every 10 minutes for probable updates. I wrote this piece of code:
@Override
public void run() {
while (true) {
// check feeds here
try {
Thread.sleep(600000);
} catch (InterruptedException ex) {
// exception handing
}
}
}
When I run it, for a day or two, it’s OK and running. But usually after 3 or 4 days, it goes to sleep and never wakes up again!!! So it doesn’t update the RSS feeds.
How can I solve this issue!?
If I have to guess I would say there’s probably a bug in the code that reads the feeds which raises an unhandled exception which in turn ends the thread. To you it seems like the thread never wakes, when in fact it dies.
It’s very unlikely that there’s a bug in the Thread.sleep method (as it is widely use almost everywhere). Anyway, debug and check to see if your thread is still alive or if it has died.