/** Start the reaper in foreground. */ public void run() { // guard { checkState(); } reap(); }
/** Work until the run flag is set to false. */ public void reap() { log.info("Reaper started."); // guard { checkState(); } while (run) { long actslice = directory.getActualSlice(); ReaperWorker worker = new ReaperWorker(directory, actslice, ttl); log.trace("Reaping timeslice " + actslice + "..."); // start thread on reap_timeslice { worker.start(); } try { long slept = 0; while (slept < directory.getTimeSliceSize() && run) { sleep(idle); slept += idle; } } catch (InterruptedException e) { // Log message, but keep working log.error("Interrupted during sleep for one timeslice: " + e.getMessage()); } // wait for reap to finish { try { worker.join(); } catch (InterruptedException e) { log.error( "Interrupted while waiting for ReaperWorker on timeslice " + actslice + ": " + e.getMessage()); } } } log.info("Reaper finished working."); }
/** Stop the thread running in the background. */ @PreDestroy public void stop_service() { // guard { checkState(); } this.run = false; try { log.info("Stopping Reaper..."); this.join(); log.info("Reaper stoped."); } catch (InterruptedException e) { log.warn("Could not wait for Reaper to stop: " + e.getMessage()); } }