如何在struts中的quartz scheduler中运行多个作业

时间:2016-06-22 22:18:06

标签: scheduler jobs struts-1

我在quartz调度程序中将多个作业实现为struts中的插件,但只使用http://www.mkyong.com/struts/struts-quartz-scheduler-integration-example/中的教程

运行第一个作业
public class QuartzPlugin implements PlugIn {

    private JobDetail job = null;
    private Trigger trigger = null;
    private Scheduler scheduler = null;

    private static Class<QuartzPlugin> clazz = QuartzPlugin.class;
    public static final String KEY_NAME = clazz.getName();

    private static Logger logger = Logger.getLogger(clazz);

    @Override
    public void destroy() {
        try {
            String METHODNAME = "destroy";
            logger.debug("entering " + KEY_NAME + " " + METHODNAME);
            scheduler.shutdown();
        } catch (SchedulerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void init(ActionServlet servlet, ModuleConfig modConfig) throws ServletException {

        String METHODNAME = "init";
        logger.debug("entering " + KEY_NAME + " " + METHODNAME);
        job = JobBuilder.newJob(SchedulerJob.class).withIdentity("anyJobName","group1").build();
        try {
            trigger = TriggerBuilder.newTrigger().withIdentity("anyTriggerName", "group1")
                    .withSchedule(CronScheduleBuilder.cronSchedule("0/30 * * * * ?")).build();

            scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            servlet.getServletContext().setAttribute(KEY_NAME, scheduler);

            // define the job and tie it to our HelloJob class
            JobDetail job2 = JobBuilder.newJob(HelloJob.class).withIdentity("job2", "group2").build();

            // Trigger the job to run on the next round minute
            Trigger trigger2 = TriggerBuilder.newTrigger().withIdentity("trigger2", "group2")
                    .withSchedule(CronScheduleBuilder.cronSchedule("15/45 * * * * ?")).build();

            // Tell quartz to schedule the job using our trigger
            scheduler.scheduleJob(job, trigger);
            scheduler.scheduleJob(job2, trigger2);

        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}

0 个答案:

没有答案