new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
System.out.println("run");
throw new SomeRandomException();
}
}, 1000, 1000);
Output: run (exception is thrown)
Here is the problem: I need a timer task to check for specific conditions in the database (or something else). It worked fine, but sometimes the database(or something else) returns some errors, exception is thrown and the timer crashes, and then no single timer task is executed again. Is there a some Timer implementation which keep working after exception is thrown in run()
.
I can
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
System.out.println("run");
throw new SomeRandomException();
} catch (Exception e) {
System.out.println("dummy catch");
}
}
}, 1000, 1000);
but this seems lame.
Other alternative is write my own implementation of Timer class, swallowing exceptions of run method (which seems also not right).