用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

Quartz 定时器初始化代码

2012-11-27 作者: 大漠孤烟举报

[java]代码库

/**
 * Quartz Cron 表达式支持到七个域 名称 是否必须 允许值 特殊字符 秒 是 0-59 , - * / 分 是 0-59 , - * /
 * 时 是 0-23 , - * / 日 是 1-31 , - * ? / L W C 月 是 1-12或 JAN-DEC , - * / 周 是
 * 1-7 或 SUN-SAT , - * ? / L C # 年 否 空 或 1970-2099 , - * /
 *
 * @param Properties
 */
private boolean initTimePaln() {
    Properties prams = Config.getInstance().getMqPrams();
    if (prams == null) {
        logger.error("MQ配置信息为空");
    }
    int timePlan = Integer.parseInt(prams.getProperty("PLANTIME"));
 
    int timePlan_refreshCache = Integer.parseInt(prams
            .getProperty("TIMEPLAN_REFRESHCACHE"));
 
    try {
        Properties props = new Properties();
        props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
                "org.quartz.simpl.SimpleThreadPool");
        props.put("org.quartz.threadPool.threadCount", "3");
        SchedulerFactory sf = new StdSchedulerFactory(props);
        if (timePlan != -1) {
            CronTrigger trigger = newTrigger()
                    .withIdentity("TimePlanTrigger", "group1")
                    .withSchedule(
                            cronSchedule("0 1 " + timePlan + " * * ?"))
                    .build();
            JobDetail job = newJob(CallDataTramsfromTask.class)
                    .withIdentity("TimpPlanJob", "group1").build();
            scheduler_TimePlan = sf.getScheduler();
            Date ft = scheduler_TimePlan.scheduleJob(job, trigger);
            logger.info(job.getKey() + "在" + ft + "开始调度执行,调度周期为"
                    + trigger.getCronExpression());
        }
 
        if (timePlan_refreshCache != -1) {
            CronTrigger trigger_refreshCachfe = newTrigger()
                    .withIdentity("TimePlanTrigger_refreshCache",
                            "group3")
                    .withSchedule(
                            cronSchedule("0 1 " + timePlan_refreshCache
                                    + " * * ?")).build();
            JobDetail job__refreshCachfe = newJob(RefreshCacheTask.class)
                    .withIdentity("TimpPlanJob_refreshCache", "group3")
                    .build();
            Date ft = scheduler_TimePlan.scheduleJob(job__refreshCachfe,
                    trigger_refreshCachfe);
            logger.info(job__refreshCachfe.getKey() + "在" + ft
                    + "开始调度执行(刷新缓存),调度周期为"
                    + trigger_refreshCachfe.getCronExpression());
        }
 
    } catch (SchedulerException e) {
        logger.error("初始化定时调度器异常" + e.getMessage());
        return false;
    }
    return true;
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...