一 配置xml如下:
二 手动获取scheduler调度对象,触发SimpleTriggerBean对象,和作业类JobDetailBean对象
public class TestJob { public static QuarzJobHelper jobHelper; /**任务调度对象*/ private static Scheduler scheduler; static AbstractApplicationContext context = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext.xml"); static{ jobHelper = (QuarzJobHelper)context.getBean("jobHelper"); /**任务调度对象*/ scheduler = (Scheduler)context.getBean("scheduler"); } public static void main(String[] args) { //从spring中获取trigger Trigger trigger = (Trigger)context.getBean("cronTrigger"); //获取job作业类 JobDetail detail = (JobDetail)context.getBean("job1"); try { //新增job scheduler.scheduleJob(detail, trigger); System.out.println(detail.getName()+","+detail.getGroup()); Thread.sleep(9000); //删除job scheduler.deleteJob(detail.getName(), detail.getGroup()); //定时任务销毁 scheduler.shutdown(); } catch (Exception e) { e.printStackTrace(); } }}