定时任务

一、

pool.scheduleAtFixedRate(new VendorsTask(), 0, syn_time_Vendors, TimeUnit.MILLISECONDS);

/*pool.scheduleWithFixedDelay(new MaterialInfoTask(), 0, syn_time_Material,
TimeUnit.MILLISECONDS);

 

二、

@SuppressWarnings("rawtypes")
@Override
public void run() {

try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logger.debug("VendorsTask start******************:" + df.format(new Date()));
Integer synchronizeNum = Integer.parseInt(Global.getConfig("SYNCHRONIZE_NUM"));
HashMap<String, Object> map = new HashMap<String, Object>();
int total = vendorsService.findAllCount();
logger.info("VendorsTask total:============" + total);
if (total > 1) {
return;
}
PageObject pageObj = new PageObject();
pageObj.setTotalCount(total);
pageObj.setPageSize(synchronizeNum);
int pageNum = pageObj.getTotalCount();
pageNum = pageNum + 10;
List<VendorsVO> list = null;
for (int i = 1; i <= pageNum; i++) {
logger.error("page=" + i);
pageObj.setPage(i);
map.put("startIndex", 0);
map.put("endIndex", synchronizeNum);
list = vendorsService.findList(map);
if (list.isEmpty()) {
break;
}
VendorsInfoTypeVO inface = new VendorsInfoTypeVO();
inface.setData(list);
send(JSON.toJSONString(inface, SerializerFeature.WriteMapNullValue));
Thread.sleep(1000);
}
logger.info("VendorsTask end@@@@@@@@@@@@@@@@@@@:" + df.format(new Date()));
} catch (Exception e) {  catch 里面不能再抛异常不然下次任务不会执行
logger.error("[VendorsTask]-->{}", e);
HashMap<String, Object> hm = StringUtils.mailMap("世强发送给朗华供应商接口=" + e.getMessage());
mailService.send(hm);  
}
}

posted @ 2019-03-05 13:37  albert_think  阅读(141)  评论(0编辑  收藏  举报