import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class TestJob implements Job{
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("ok");
}
}
<pre name="code" class="html">import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import com.ai.appframe2.util.ResourceUtil;
import com.asiainfo.appframe.ext.exeframe.task.TaskFrameWork;
public class NewsVisitCountTask {
private transient static Log log = LogFactory.getLog(TestTask.class);
public void doTask(String taskCode,String taskID) throws Exception {
String[] args = new String[]{taskCode,"0",taskID};
//载入配置參数
Properties prop = ResourceUtil.loadPropertiesFromClassPath("task/task.properties", "task", true);
//生成调度
StdSchedulerFactory scheduler = new StdSchedulerFactory(prop);
Scheduler schedu = scheduler.getDefaultScheduler();
//绑定job
//创建jobDetail实例,绑定Job实现类
//指明job的名称,所在组的名称,以及绑定job类
JobDetail job = new JobDetail("TaskScanJob", "TaskScanJobGrp", TestJob.class);
//默认的scanDataJob.cron的參数。每隔1分钟
String scanDataJobCron = "0 0/1 * * * ?";
//加入触发器
Trigger trigger = new CronTrigger("TaskScanTrigger", "TaskScanTriggerGrp", scanDataJobCron);<pre name="code" class="html"> //将任务和触发器加入调度
schedu.scheduleJob(job, trigger);
schedu.start();
}
public static void main(String[] args) throws Exception {
NewsVisitCountTask task = new NewsVisitCountTask();
task.doTask("EMP_STAFF_YEAR_A","1000000002");
System.out.println("ok");
}
}本人才写的源码。这里是公司的须要我才专门研究了一下下,结果发现超级好用