CronScheduleLogManager.java
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.sitech.ibnms.config.sync.adaptor;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.sitech.ibnms.config.sync.service.CronScheduleLogService;
import com.sitech.ismp.messageObject.ScheduleLog;
public class CronScheduleLogManager implements Runnable {
protected static Logger logger = Logger.getLogger("LOGGER");
private boolean isRun = true;
private static List<ScheduleLog> queue = new ArrayList<ScheduleLog>();
private CronScheduleLogService logService = new CronScheduleLogService();
@Override
public void run() {
while(isRun){
try {
refresh();
} catch (Exception e) {
logger.error("Exception while refresh CronScheduleLog", e);
}
try {
Thread.sleep(3000L);
} catch (InterruptedException e) {
logger.error("Exception while CronScheduleLogManager sleeping",e);
}
}
}
public static void save(ScheduleLog log) {
synchronized (queue) {
queue.add(log);
}
}
private List<ScheduleLog> poll() {
List<ScheduleLog> temp = new ArrayList<ScheduleLog>();
synchronized (queue) {
temp.addAll(queue);
queue.clear();
}
return temp;
}
private void refresh(){
List<ScheduleLog> logs = poll();
for(ScheduleLog log:logs){
logService.insertCronScheduleLogs(log);
}
}
}