使用Elastic_Job分布式定时框架,在初始化多个定时任务时没有全部初始化成功
2018-08-23 16:51
561 查看
今天遇到了一个很奇怪的问题,在初始化定时任务时,只有两个任务初始化成功,其他三个死活不行。我采用的是5个定时任务分别用5个初始化配置,代码如下
public class CouponJobConfig {
/** * 初始化调度任务 * @return */ @Bean(initMethod = "init") public JobScheduler simpleJobScheduler15() { GlobalProperties globalProperties = ApplicationUtil.getBean(GlobalProperties.class); return new JobScheduler(createRegistryCenter(globalProperties), createJobConfiguration(globalProperties)); } /** * zookpeer 注册中心,一个任务有一个 namespace * demo-job 这个为1个zk环境的下的1个namespace 可以有多个 1个namespace下有多个job * @return */ private static CoordinatorRegistryCenter createRegistryCenter(GlobalProperties globalProperties) { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter( new ZookeeperConfiguration(globalProperties.getServerList(), globalProperties.getNamespace())); regCenter.init(); return regCenter; } /** * 创建任务的配置信息,执行信息 * mySimpleTest 为jobname 0/10 * * * * ? 为cron表达式 分片对应内容 jobParameter 自定义参数 * @return */ private static LiteJobConfiguration createJobConfiguration(GlobalProperties globalProperties) { JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(globalProperties.getJobname(), globalProperties.getCouponInfo(), 1).build(); SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, SimpleJobCoupon.class.getCanonicalName()); LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build(); return simpleJobRootConfig; }
}
通过打印初始化信息标记,我发现只有两个是初始化成功的,其他三个都没进行初始化,推测应该是Bean初始化这边出了问题,其他三个初始化信息没有识别执行。之后我将五个任务的初始化合并在一块,即第一次得到配置信息存起来,再每个方法调用zookeeper注册中心和创建执行任务的配置信息解决问题
应该还能通过改变@Bean(initMethod = “init”,name=”**“)来解决问题
阅读更多相关文章推荐
- Elastic-Job - 分布式定时任务框架
- Elastic-Job - 分布式定时任务框架
- Elastic-Job-分布式定时任务框架(张亮原著)
- Elastic-Job - 分布式定时任务框架
- Elastic-Job - 分布式定时任务框架
- Elastic-Job——分布式定时任务框架
- Elastic-Job - 分布式定时任务框架
- Elastic-Job——分布式定时任务框架
- Elastic-Job - 分布式定时任务框架
- Elastic-Job - 分布式定时任务框架
- Quartz小记(一):Elastic-Job - 分布式定时任务框架
- Elastic-Job - 分布式定时任务框架
- Quartz小记(一):Elastic-Job - 分布式定时任务框架
- Elastic-Job - 分布式定时任务框架
- 分布式定时任务——elastic-job
- 【niubi-job——一个分布式的任务调度框架】----如何开发一个niubi-job的定时任务
- 分布式定时任务框架比较,spring batch, tbschedule jobserver
- linux 使用crontab添加定时任务,日志显示已经执行但是任务没有成功调用解决方法
- Java任务调度框架Quartz入门教程指南(二) 使用job、trigger、schedule调用定时任务
- 新一代分布式任务调度框架:当当elastic-job开源项目的10项特性