我在conf配置下custom里面加了一个timer配置,cron.com.backend.timer.StatisticJob=0 0 0 * * ? *;
我在conf配置下custom里面加了一个timer配置,
配置如下:
cron.com.backend.timer.OnlinePlayerJob=0 */5 * * * ?
cron.com.backend.timer.StatisticJob=0 0 0 * * ? *
在ioc下面,添加了一个js,如下:
var ioc = {
"onlinePlayerJob" :{
"type" :"com.backend.timer.OnlinePlayerJob",
"fields":{dao:{refer:"backendDao"}}
},
"statisticJob" :{
"type" :"com.backend.timer.StatisticJob"
}
};
具体的操作如下:
public class StatisticJob implements Job {
private static final Logger log = Logger.getLogger(StatisticJob.class);
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
long now =context.getFireTime().getTime();
int nowTime = Long.valueOf(now/1000).intValue();
int beginTime = nowTime - 24 * 60 * 60;
Dao backendDao = LoginServerManager.getInstance().getDao();
List<Dblog> serverlist = backendDao.query(Dblog.class,null);
for (Dblog ser : serverlist) {
try{
SimpleDataSource source = DbConfigUtil.getInstance().GetDS(ser);
if(source == null){
continue;
}
Dao dao = new NutDao(source);
//要统计的物品初始化
final HashMap<Integer, ItemDailyStatistic> itemList = new HashMap<>();
for(ItemInfo item : ItemManger.getInstance().getItemList().values()){
if(item.getNeedSaveLog() <= 1){
continue;
}
ItemDailyStatistic info = new ItemDailyStatistic();
info.setItemDataId(item.getItemId());
info.setTime(nowTime);
info.setServerId(ser.getServerId());
itemList.put(item.getItemId(), info);
}
//统计货币初始化
final HashMap<Integer, MoneyDailyStatistic> moneyList = new HashMap<>();
for(int i = 1;i <= 9;i++){
MoneyDailyStatistic info = new MoneyDailyStatistic();
info.setMoneyType(i);
info.setTime(nowTime);
info.setServerId(ser.getServerId());
moneyList.put(i, info);
}
itemDailyStatisticProduct(dao, now, beginTime, itemList);
itemDailyStatisticCost(dao, now, beginTime, itemList);
itemDailyStatisticRemain(backendDao,itemList,ser.getServerId());
moneyDailyStatisticProduct(dao, now, beginTime, moneyList);
moneyDailyStatisticCost(dao, now, beginTime, moneyList);
moneyDailyStatisticRemain(backendDao,moneyList,ser.getServerId());
}catch(Exception e){
log.error(e,e);
}
}
}
但是我不知道,配置的timer,是怎么执行的