延时任务执行,定时结束,定时终止
List<Object> List = xxxxMapper.selectByExample(example);
long startTime = System.currentTimeMillis();
ConcurrentHashMap<String, ScheduledFuture> taskMap = new ConcurrentHashMap<>(1);
ScheduledExecutorService scheduleExecutor = new ScheduledThreadPoolExecutor(1);
ScheduledFuture scheduledFuture = scheduleExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
if (getReport(recordList)) {
logger.info("延时执行终止");
taskMap.get("scheduledFuture").cancel(true);
scheduleExecutor.shutdown();
}
} catch (Exception e) {
logger.error("延时执行批量导入任务异常:"+e);
}
}
}, 0, 30, TimeUnit.SECONDS);
taskMap.put("scheduledFuture", scheduledFuture);
long endTime = System.currentTimeMillis();
logger.info("时长 :"+(endTime-startTime));
private boolean getReport(List<Object> List) throws IOException {
List<Object> tmpList=new ArrayList<Object>();
for (int i = 0; i < 10; i++) {
if (recordList.size() > 0) {
tmpList.add(recordList.get(0));
recordList.remove(0);
}
}
for (Object data: tmpList) {
Map<String, String> params = new HashMap<>();
JSONObject resJson;
try {
} catch (Exception e)
logger.error("败");
continue;
}
}
logger.info("批量:"+tmpList.size());
return recordList.size() == 0;
}