new Timer().scheduleAtFixedRate(new TimerTask() { @Override public void run() { System.out.println("run"); throw new SomeRandomException(); } }, 1000, 1000);
Exit: start (exception thrown)
Here's 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, an exception is thrown and a timer fails, and then another timer task fails. Is there any implementation of Timer that continues to work after an exception is thrown into 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 it seems lame.
Another alternative is to write my own implementation of the Timer class, swallowing the exceptions of the run method (which seems also wrong).
java timer
fiction
source share