1 package net.sf.flock.util;
2
3 import org.apache.log4j.LogManager;
4 import org.apache.log4j.Logger;
5
6 /***
7 * @version $Revision$
8 * @author $Author$
9 */
10 public class SchedulerThread extends Thread {
11
12 private final static Logger LOGGER = LogManager.getLogger(SchedulerThread.class);
13
14 private final int sleepMinutes;
15 private final Runnable task;
16
17 public SchedulerThread(int sleepMinutes, Runnable task) {
18 super("SchedulerThread");
19 this.setDaemon(true);
20 this.sleepMinutes = sleepMinutes;
21 this.task = task;
22 }
23
24 public void run() {
25 LOGGER.info("Scheduler thread started");
26 try {
27 while (true) {
28 Thread.sleep(sleepMinutes * 60 * 1000);
29 LOGGER.debug("Scheduler running task");
30 this.task.run();
31 }
32 } catch (InterruptedException e) {
33 LOGGER.warn("Scheduler thread interrupted", e);
34 } finally {
35 LOGGER.info("Scheduler thread stopped");
36 }
37 }
38
39 }
This page was automatically generated by Maven