java 触发任务

    public void autoShelf()
    {

        SchedulerFactory schedulerFactory = (StdSchedulerFactory) ServletActionContext
                .getServletContext().getAttribute(
                        "org.quartz.impl.StdSchedulerFactory.KEY");
        Scheduler sche = null;
        try
        {
            if (null == schedulerFactory)
            {
                logger.error("start autoShelf is failed");
                return;
            }
            sche = schedulerFactory.getScheduler();
            sche.start();
        }
        catch (SchedulerException e)
        {
            e.printStackTrace();
        }
        String AutoShelfJobname = "AutoShelfJob" + new Date();
        String AutoShelfJobGroup = "AutoShelfJobGroup" + new Date();
        JobDetail jobDetail = new JobDetail(AutoShelfJobname,
                AutoShelfJobGroup, UpRuleTask.class);

        long startTime = System.currentTimeMillis() + 3000L;
        String triggername = "autoShelfTrigger" + new Date();
        SimpleTrigger trigger = new SimpleTrigger(triggername, null, new Date(
                startTime), null, 0, 0L);
        try
        {
            sche.scheduleJob(jobDetail, trigger);
        }
        catch (SchedulerException e)
        {
            e.printStackTrace();
        }
    }

你可能感兴趣的:(java,触发器)