|
|||||||||||||||||||
This license of Clover is provided to support the development of Flock only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover. | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SchedulerThread.java | - | 0% | 0% | 0% |
|
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 | 0 |
public SchedulerThread(int sleepMinutes, Runnable task) { |
18 | 0 |
super("SchedulerThread"); |
19 | 0 |
this.setDaemon(true); |
20 | 0 |
this.sleepMinutes = sleepMinutes; |
21 | 0 |
this.task = task; |
22 |
} |
|
23 |
|
|
24 | 0 |
public void run() { |
25 | 0 |
LOGGER.info("Scheduler thread started"); |
26 | 0 |
try { |
27 | 0 |
while (true) { |
28 | 0 |
Thread.sleep(sleepMinutes * 60 * 1000); |
29 | 0 |
LOGGER.debug("Scheduler running task"); |
30 | 0 |
this.task.run(); |
31 |
} |
|
32 |
} catch (InterruptedException e) { |
|
33 | 0 |
LOGGER.warn("Scheduler thread interrupted", e); |
34 |
} finally { |
|
35 | 0 |
LOGGER.info("Scheduler thread stopped"); |
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
} |
|
40 |
|
|