最近项目需要弄多个定时任务用爬虫批量抓取数据,用的spring定时job功能,简单总结下来:
package util;
import org.apache.log4j.*;
public class TaskJob {
package util;
import org.apache.log4j.*;
public class TaskJob {
public static Logger log = Logger
.getLogger(TaskJob.class);
public void SayHello() {
// TODO Auto-generated method stub
try {
log.info("处理任务开始>........");
// 业务逻辑代码调用
System.out.println("时间[" + new java.util.Date().toLocaleString()
+ "]----->大家好啊!");
log.info("处理任务结束!");
} catch (Exception e) {
log.error("处理任务出现异常", e);
}
}
}
2.接下来的在spring 里配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean name="taskJob" class="util.TaskJob" />
<bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailF actoryBean">
<property name="targetObject">
.getLogger(TaskJob.class);
public void SayHello() {
// TODO Auto-generated method stub
try {
log.info("处理任务开始>........");
// 业务逻辑代码调用
System.out.println("时间[" + new java.util.Date().toLocaleString()
+ "]----->大家好啊!");
log.info("处理任务结束!");
} catch (Exception e) {
log.error("处理任务出现异常", e);
}
}
}
2.接下来的在spring 里配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean name="taskJob" class="util.TaskJob" />
<bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailF actoryBean">
<property name="targetObject">
转载于:http://blog.itpub.net/29119536/viewspace-1745601/