/**
* 添加任务
*/
private void addTasks() {
List<UrlRequest> urlReqs = new ArrayList<UrlRequest>();
List<Task> ts = new TaskDao().getRunnableTasks();
for (Task task : ts) {
if (!TaskCenter.taskState.keySet().contains(task)) {
TaskCenter.taskState.put(task, new ArrayList<UrlState>());
TaskCenter.taskCount.put(task, 0);
new TaskDao().updateTaskUpdatetime(task);
logger.info("run task : " + task.getTname() + " url : "
+ task.getTurl());
UrlRequest urlReq = new UrlRequest(task.getTurl(), task);
urlReqs.add(urlReq);
}
}
if (urlReqs.size() > 0) {
new TaskDao().updateTaskNextrun(ts); // 更新任务启动时间
TaskCenter.addUrl(urlReqs);
}
}