Skip to content

Commit

Permalink
Catch all thrown stuff in AsyncUpdater
Browse files Browse the repository at this point in the history
To "protect" the fixed rate scheduling from being aborted in ScheduledExecutorService
  • Loading branch information
runeflobakk committed Mar 4, 2025
1 parent c62ce4a commit 5995073
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/no/digipost/monitoring/async/AsyncUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.Logger;

import static java.util.logging.Level.WARNING;

class AsyncUpdater implements Runnable {

private static final Logger LOG = Logger.getLogger(AsyncUpdater.class.getName());
Expand All @@ -46,8 +47,10 @@ public void run() {
updateNewValues.run();
lastUpdate = clock.instant();
lastUpdateSuccessful = true;
} catch (Exception e) {
LOG.log(Level.WARNING, "Unexpected exception in updater '" + updaterName + "' while updating metrics.", e);
} catch (Throwable e) {
LOG.log(WARNING,
"Unexpected exception in updater '" + updaterName + "' while updating metrics: " +
e.getClass().getSimpleName() + " " + e.getMessage(), e);
lastUpdateSuccessful = false;
}
}
Expand Down

0 comments on commit 5995073

Please sign in to comment.