jfinal 定时任务
1、去quartz官网下载 定时任务jar包(http://www.quartz-scheduler.org/)quartz-*.*.*.jar
2、创建定时任务:
public class SetArea implements Job{
public void execute(JobExecutionContext arg0) throws JobExecutionException {
// TODO Auto-generated method stub
List<Record> record = Db
.find("SELECT F_TEMID,F_NAME,F_IDCARD,F_PHONE,F_PARENTID FROM T_TEM_TOURISTINFO WHERE F_PHONE IS NOT NULL AND F_AREA IS NULL");
for(int i=0;i<record.size();i++){
String F_PHONE = record.get(i).get("F_PHONE");
String F_IDCARD = record.get(i).get("F_IDCARD");
String area = PhoneUtil.getGeo(F_PHONE,"86").substring(0,3);
if(area.equals("黑龙江")||area.equals("内蒙古")){
}else{
area = area.substring(0,2);
}
//logger.info("F_PHONE=="+F_PHONE+"F_IDCARD=="+"area=="+area);
String sql = "update T_TEM_TOURISTINFO set F_AREA='"+area+"' where (f_phone='"+F_PHONE+"' or F_PARENTID ='"+F_IDCARD+"')";
Db.update(sql);
}
}
}
3、配置文件:job.properties
job=cn.sdta.tuandui.job.SetArea
cron=0 0 0/2 * * ?
enable=true
4、jfinal定时任务配置
public void configPlugin(Plugins me) {
/*
* 定时任务
*/
QuartzPlugin quartzPlugin = new QuartzPlugin("job.properties");
//quartzPlugin.version("1");//可控制版本
me.add(quartzPlugin);
}
本文原创,转载必追究版权。