PeriodicalReloadStrategy implements ReloadStrategy { @Override public void register(final Reloadable resource) { LOG.debug("Registering resource " + resource + " with reload time of " + duration + " " + timeUnit.toString().toLowerCase()); TimerTask timerTask = new TimerTask() { @Override public void run() { try { resource.reload(); } catch (Exception e) { LOG.warn("Periodical resource reload failed. Will re-try at the next scheduled time.", e); } } }; timerTask.run(); tasks.put(resource, timerTask); timer.schedule(timerTask, timeUnit.toMillis(duration), timeUnit.toMillis(duration)); } PeriodicalReloadStrategy(long duration, TimeUnit timeUnit); @Override void register(final Reloadable resource); @Override void deregister(Reloadable resource); @Override String toString();  }
@Test void suppressesException() { doThrow(new IllegalStateException()).when(reloadable).reload(); PeriodicalReloadStrategy strategy = new PeriodicalReloadStrategy(60, TimeUnit.SECONDS); strategy.register(reloadable); verify(reloadable, times(1)).reload(); }