您的位置:首页 > 其它

使用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=”**“)来解决问题

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: