Catch exceptions thrown in repeating tasks to avoid subsequent executions from being cancelled

This commit is contained in:
Luck 2018-03-31 11:13:27 +01:00
parent cbeaaca7af
commit 6dba778e60
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -38,7 +38,15 @@ public abstract class RepeatingTask {
protected RepeatingTask(long time, TimeUnit unit, String nameFormat) {
this.executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat(nameFormat).build());
this.executor.scheduleAtFixedRate(this::tick, time, time, unit);
this.executor.scheduleAtFixedRate(this::run, time, time, unit);
}
private void run() {
try {
tick();
} catch (Exception e) {
e.printStackTrace();
}
}
protected abstract void tick();