public void safeCleanup() { if( daysToKeep <= 0 || lastError.get() > 0 ){ return; } try{ long start = System.currentTimeMillis(); storage.cleanup(daysToKeep, appType); lastSave.set(dateUtil.now().getTime()); log.info("Performed cleanup in {}ms", System.currentTimeMillis() - start); }catch(Exception e){ Throwable cause = firstNonNull(getRootCause(e), e); log.warn("Failed to cleanup stats. Error type: {}, Message: {}", cause.getClass().getName(), cause.getMessage()); log.debug("Failed to cleanup stats.", e); } }