`

基于zookeeper和quartz实现分布式定时调度

阅读更多

目的

利用zookeeper的特性,来控制quartz实现分布式调度,保证quartz的单点运行,同时解除quartz自身分布式部署对数据库的依赖,保证同一时刻只有一个quartz应用在执行任务。

实现方式

利用zk的分布式独占锁,控制quartz应用执行节点,让拿到独占锁的quartz应用执行调度,没有拿到独占锁的quartz处理等待状态。

类图


 

核心代码

 

public class TriggerBean {

    /**
     * 标识
     */
    private String key;
    /**
     * 所属组
     */
    private String group;
    /**
     * 描述
     */
    private String description;
    /**
     * 启动时间
     */
    private String startTime;
    /**
     * 结束时间
     */
    private String endTime;
    /**
     * 优先级
     */
    private Integer priority;
    /**
     * 日历名称
     */
    private String calendarName;
    /**
     * 失火指令(参数0,1,2)
     * MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY = -1
     * MISFIRE_INSTRUCTION_SMART_POLICY = 0 (默认)
     * MISFIRE_INSTRUCTION_FIRE_ONCE_NOW = 1
     * MISFIRE_INSTRUCTION_DO_NOTHING = 2
     */
    private Integer misfireInstruction;
    /**
     * 任务代理类
     */
    private JobDetailProxyBean jobDetail;

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public String getCalendarName() {
        return calendarName;
    }

    public void setCalendarName(String calendarName) {
        this.calendarName = calendarName;
    }

    public Integer getMisfireInstruction() {
        return misfireInstruction;
    }

    public void setMisfireInstruction(Integer misfireInstruction) {
        this.misfireInstruction = misfireInstruction;
    }

    public JobDetailProxyBean getJobDetail() {
        return jobDetail;
    }

    public void setJobDetail(JobDetailProxyBean jobDetail) {
        this.jobDetail = jobDetail;
    }
}
public class CronTriggerBean extends TriggerBean {

    /**
     * CRON表达式
     */
    private String cronExpression;

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }
}
 

 

 

public class SimpleTriggerBean extends TriggerBean {

    /**
     * 时间间隔(秒)
     */
    private Integer interval;
    /**
     * 重复次数(默认:-1为无限循环)
     */
    private Integer repeatCount;

    public Integer getInterval() {
        return interval;
    }

    public void setInterval(Integer interval) {
        this.interval = interval;
    }

    public Integer getRepeatCount() {
        return repeatCount;
    }

    public void setRepeatCount(Integer repeatCount) {
        this.repeatCount = repeatCount;
    }
}
public class SchedulerFactoryBean implements InitializingBean {

    protected static Logger logger = Logger.getLogger(SchedulerFactoryBean.class);
    /**
     * 触发器列表
     */
    private List<Object> triggers;
    /**
     * zooKeeper工厂
     */
    private ZookeeperFactory zooKeeperFactory;

    /**
     * Spring初始化方法
     * @throws SchedulerException
     */
    public void afterPropertiesSet() throws SchedulerException {
        this.initSchedulerFactory();
    }

    /**
     * 初始化调度器工厂
     * @throws SchedulerException
     */
    public void initSchedulerFactory() throws SchedulerException {
        //初始化StdSchedulerFactory
        StdSchedulerFactory schedulerFactory = SchedulerUtils.initStdSchedulerFactory();
        //获取调度器
        Scheduler scheduler = schedulerFactory.getScheduler();
        //装载调度器
        for(Object triggerObject : this.getTriggers()){
            if(triggerObject instanceof CronTriggerBean){
                CronTriggerBean cronTriggerBean = (CronTriggerBean)triggerObject;
                //获取任务代理类对象
                JobDetailProxyBean jobDetailProxyBean = cronTriggerBean.getJobDetail();
                //装配任务
                JobDetail jobDetail = SchedulerUtils.assemblyJobDetail(jobDetailProxyBean);
                //设置zooKeeper连接工厂
                jobDetail.getJobDataMap().put("zooKeeperFactory",this.getZooKeeperFactory());
                //装配触发器
                CronTrigger cronTrigger =  SchedulerUtils.assemblyCronTrigger(cronTriggerBean);
                scheduler.scheduleJob(jobDetail, cronTrigger);
//                System.out.println("CronTriggerBean");
            }else{
                SimpleTriggerBean simpleTriggerBean = (SimpleTriggerBean)triggerObject;
                //获取任务代理类对象
                JobDetailProxyBean jobDetailProxyBean = simpleTriggerBean.getJobDetail();
                //装配任务
                JobDetail jobDetail = SchedulerUtils.assemblyJobDetail(jobDetailProxyBean);
                //设置zooKeeper连接工厂
                jobDetail.getJobDataMap().put("zooKeeperFactory",this.getZooKeeperFactory());
                //装配触发器
                SimpleTrigger simpleTrigger =  SchedulerUtils.assemblySimpleTrigger(simpleTriggerBean);
                scheduler.scheduleJob(jobDetail, simpleTrigger);
//                System.out.println("SimpleTriggerBean");
            }
        }

        scheduler.start();
        logger.info("调度器已启动");
    }

    public List<Object> getTriggers() {
        return triggers;
    }

    public void setTriggers(List<Object> triggers) {
        this.triggers = triggers;
    }

    public ZookeeperFactory getZooKeeperFactory() {
        return zooKeeperFactory;
    }

    public void setZooKeeperFactory(ZookeeperFactory zooKeeperFactory) {
        this.zooKeeperFactory = zooKeeperFactory;
    }
}

 

package com.ab.scheduling.quartz;

import com.ab.scheduling.quartz.constant.Constant;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.state.ConnectionState;
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.log4j.Logger;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.springframework.beans.factory.InitializingBean;

import java.util.Collections;
import java.util.List;

/**
 * Zookeeper 工厂类
 * Date: 14-4-2
 * Time: 下午4:03
 */
public class ZookeeperFactory implements InitializingBean{

    public static Logger logger = Logger.getLogger(ZookeeperFactory.class);

    /**
     * zookeeper服务地址
     */
    private String hosts;
    /**
     * 回话的超时时间(毫秒)
     */
    private Integer sessionTimeOut;
    /**
     * 连接的超时时间(毫秒)
     */
    private Integer connectionTimeOut;
    /**
     * 命名空间
     **/
    private String nameSpace;
    /**
     * zookeeper管理对象
     */
    private CuratorFramework zkTools;
    /**
     * 独享队列节点
     */
    private String monopolyQueueNode;
    /**
     * 连接状态
     */
    private String connectionState;
    /**
     * 会话ID
     */
    private long sessionId;

    /**
     * Spring初始化方法
     */
    public void afterPropertiesSet(){
        this.connection();
        this.addListener();
    }

    /**
     * 连接
     */
    public void connection(){
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, Integer.MAX_VALUE);
        zkTools = CuratorFrameworkFactory
                .builder()
                .connectString(hosts)
                .namespace(nameSpace)
                .retryPolicy(retryPolicy)
                .connectionTimeoutMs(connectionTimeOut == null ? 30000 : connectionTimeOut)
                .sessionTimeoutMs(sessionTimeOut == null ? 30000 : sessionTimeOut)
                .build();
        zkTools.start();
    }

    /**
     * 连接状态监听
     */
    public void addListener(){
        zkTools.getConnectionStateListenable().addListener(new ConnectionStateListener() {
            public void stateChanged(CuratorFramework client, ConnectionState newState) {
                if (newState.equals(ConnectionState.CONNECTED)) {
                    logger.info("连接");
                    connectionState = "CONNECTED";
                    try {
                        sessionId = zkTools.getZookeeperClient().getZooKeeper().getSessionId();
                        registerMonopolyQueue();
                    } catch (Exception e) {
                        logger.error("注册独占队列失败");
                    }
                }
                if (newState.equals(ConnectionState.RECONNECTED)) {
                    logger.info("重新连接");
                    connectionState = "CONNECTED";
                    try {
                        if(sessionId != zkTools.getZookeeperClient().getZooKeeper().getSessionId()) {
                            registerMonopolyQueue();
                        }
                    } catch (Exception e) {
                        logger.error("注册独占队列失败");
                    }
                }
                if (newState.equals(ConnectionState.LOST)) {
                    logger.info("丢失");
                    connectionState = "LOST";
                }
                if (newState.equals(ConnectionState.SUSPENDED)) {
                    logger.info("暂停");
                    connectionState = "SUSPENDED";
                }
                if (newState.equals(ConnectionState.READ_ONLY)) {
                    logger.info("只读");
                    connectionState = "READ_ONLY";
                }
            }
        });
    }



    /**
     * 注册独占队列
     */
    private void registerMonopolyQueue() throws Exception {
        if(zkTools.checkExists().watched().forPath(Constant.MONOPOLY) == null){
            zkTools.create()
                    .withMode(CreateMode.PERSISTENT)
                    .withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)
                    .forPath(Constant.MONOPOLY);
            logger.info("创建独享锁队列节点成功!");
        }
        if(monopolyQueueNode == null || (monopolyQueueNode != null && zkTools.checkExists().forPath(monopolyQueueNode)==null)) {
            monopolyQueueNode = zkTools.create()
                    .withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
                    .withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)
                    .forPath(Constant.MONOPOLY + Constant.SEPARATOR + Constant.QUEUE_NODE);
            logger.info("成功加入独享锁队列");
        }
    }

    /**
     * 获得独占锁的执行权限
     * @return 执行权限标识
     * @throws KeeperException
     * @throws InterruptedException
     */
    public boolean getMonopolyLock() throws Exception {
        boolean flag = false;
        if(connectionState != null && (connectionState.equals("CONNECTED") || connectionState.equals("RECONNECTED"))){
            List<String> nodes = zkTools.getChildren().watched().forPath(Constant.MONOPOLY);
            if(nodes.size() > 0){
                Collections.sort(nodes);
                //判断当前应用是否在队列的第一位
                if((Constant.SEPARATOR + Constant.MONOPOLY + Constant.SEPARATOR + nodes.get(0)).equals(monopolyQueueNode)){
                    flag = true;
                }
            }
        }
        return flag;
    }

    /**
     * 关闭连接
     */
    public void close(){
        if(zkTools != null){
            zkTools.close();
            zkTools = null;
        }
    }

    public String getHosts() {
        return hosts;
    }

    public void setHosts(String hosts) {
        this.hosts = hosts;
    }

    public Integer getSessionTimeOut() {
        return sessionTimeOut;
    }

    public void setSessionTimeOut(Integer sessionTimeOut) {
        this.sessionTimeOut = sessionTimeOut;
    }

    public Integer getConnectionTimeOut() {
        return connectionTimeOut;
    }

    public void setConnectionTimeOut(Integer connectionTimeOut) {
        this.connectionTimeOut = connectionTimeOut;
    }

    public String getNameSpace() {
        return nameSpace;
    }

    public void setNameSpace(String nameSpace) {
        this.nameSpace = nameSpace;
    }
}

 

package com.ab.scheduling.quartz.common;

import com.ab.scheduling.quartz.JobDetailProxyBean;
import com.ab.scheduling.quartz.CronTriggerBean;
import com.ab.scheduling.quartz.SimpleTriggerBean;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.simpl.SimpleThreadPool;

import java.util.Properties;

/**
 * Quartz调度工具类
 * Date: 14-5-15
 * Time: 下午6:10
 */
public class SchedulerUtils {

    protected static Logger logger = Logger.getLogger(SchedulerUtils.class);

    /**
     * 初始化StdSchedulerFactory
     * @return StdSchedulerFactory
     */
    public static StdSchedulerFactory initStdSchedulerFactory() {
        StdSchedulerFactory schedulerFactory = null;
        try{
            schedulerFactory = (StdSchedulerFactory) Class.forName(StdSchedulerFactory.class.getName()).newInstance();
            Properties mergedProps = new Properties();
            // 设置Quartz线程池设置
            mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
            mergedProps.setProperty("org.quartz.threadPool.threadCount", Integer.toString(10));

            schedulerFactory.initialize(mergedProps);
        } catch (Exception e){
            logger.error("初始化StdSchedulerFactory失败");
            logger.error(e);
        }
        return schedulerFactory;
    }

    /**
     * 装配任务
     * @param jobDetail 任务代理类
     * @return JobDetail
     */
    public static JobDetail assemblyJobDetail(JobDetailProxyBean jobDetail){

        JobBuilder jobBuilder = JobBuilder.newJob(jobDetail.getClass());
        //设置JobDetail身份标识与所属组
        String key = jobDetail.getKey();
        if(StringUtils.isNotBlank(key)){
            jobBuilder = jobBuilder.withIdentity(key, jobDetail.getGroup());
        }else{
            jobBuilder = jobBuilder.withIdentity(IdentityUtils.generatorUUID("JOB"), jobDetail.getGroup());
        }

        //设置任务描述
        if(StringUtils.isNotBlank(jobDetail.getDescription())){
            jobBuilder = jobBuilder.withDescription(jobDetail.getDescription());
        }

        //设置JobDetail数据参数
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put("targetObject",jobDetail.getTargetObject());                   //目标对象
        jobDataMap.put("targetMethod",jobDetail.getTargetMethod());                   //目标方法
        jobDataMap.put("mode", jobDetail.getMode());                                  //运行模式
        jobBuilder = jobBuilder.usingJobData(jobDataMap);

        return jobBuilder.build();
    }

    /**
     * 装配表达式触发器
     * @param cronTriggerBean 表达式触发器
     * @return 表达式触发器
     */
    public static CronTrigger assemblyCronTrigger(CronTriggerBean cronTriggerBean){

        TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();

        //设置触发器身份标识与所属组
        String key = cronTriggerBean.getKey();
        if(StringUtils.isNotBlank(key)){
            triggerBuilder = triggerBuilder.withIdentity(key, cronTriggerBean.getGroup());
        }else{
            triggerBuilder = triggerBuilder.withIdentity(IdentityUtils.generatorUUID("CronTrigger"), cronTriggerBean.getGroup());
        }
        //设置描述
        if(StringUtils.isNotBlank(cronTriggerBean.getDescription())){
            triggerBuilder = triggerBuilder.withDescription(cronTriggerBean.getDescription());
        }
        //设置启动时间
        if(StringUtils.isNotBlank(cronTriggerBean.getStartTime())){
            triggerBuilder = triggerBuilder.startAt(DateUtils.StringToDate(cronTriggerBean.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
        }else{
            triggerBuilder = triggerBuilder.startNow();      //当启动时间为空默认立即启动调度器
        }
        //设置结束时间
        if(StringUtils.isNotBlank(cronTriggerBean.getEndTime())){
            triggerBuilder = triggerBuilder.endAt(DateUtils.StringToDate(cronTriggerBean.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
        }
        //设置优先级
        if(cronTriggerBean.getPriority() != null){
            triggerBuilder = triggerBuilder.withPriority(cronTriggerBean.getPriority());
        }

        //设置Cron表达式(不允许为空)与集火指令
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronTriggerBean.getCronExpression());
        if(cronTriggerBean.getMisfireInstruction() != null){
            if(cronTriggerBean.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) {
                cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionIgnoreMisfires();
            }
            if(cronTriggerBean.getMisfireInstruction() == CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) {
                cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionFireAndProceed();
            }
            if(cronTriggerBean.getMisfireInstruction() == CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING) {
                cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionDoNothing();
            }
        }
        triggerBuilder = triggerBuilder.withSchedule(cronScheduleBuilder);

        return (CronTrigger)triggerBuilder.build();
    }

    /**
     * 装配简单触发器
     * @param simpleTriggerBean 简单触发器
     * @return 简单触发器
     */
    public static SimpleTrigger assemblySimpleTrigger(SimpleTriggerBean simpleTriggerBean){

        TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();

        //设置触发器身份标识与所属组
        String key = simpleTriggerBean.getKey();
        if(StringUtils.isNotBlank(key)){
            triggerBuilder = triggerBuilder.withIdentity(key, simpleTriggerBean.getGroup());
        }else{
            triggerBuilder = triggerBuilder.withIdentity(IdentityUtils.generatorUUID("SimpleTrigger"), simpleTriggerBean.getGroup());
        }
        //设置描述
        if(StringUtils.isNotBlank(simpleTriggerBean.getDescription())){
            triggerBuilder = triggerBuilder.withDescription(simpleTriggerBean.getDescription());
        }
        //设置启动时间
        if(StringUtils.isNotBlank(simpleTriggerBean.getStartTime())){
            triggerBuilder = triggerBuilder.startAt(DateUtils.StringToDate(simpleTriggerBean.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
        }else{
            triggerBuilder = triggerBuilder.startNow();      //当启动时间为空默认立即启动调度器
        }
        //设置结束时间
        if(StringUtils.isNotBlank(simpleTriggerBean.getEndTime())){
            triggerBuilder = triggerBuilder.endAt(DateUtils.StringToDate(simpleTriggerBean.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
        }
        //设置优先级
        if(simpleTriggerBean.getPriority() != null){
            triggerBuilder = triggerBuilder.withPriority(simpleTriggerBean.getPriority());
        }

        //设置简单触发器 时间间隔(不允许为空)、执行次数(默认为-1)与集火指令
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(20).withRepeatCount(-1);
        simpleScheduleBuilder = simpleScheduleBuilder.withIntervalInSeconds(simpleTriggerBean.getInterval());
        if(simpleTriggerBean.getRepeatCount() != null){
            simpleScheduleBuilder = simpleScheduleBuilder.withRepeatCount(simpleTriggerBean.getRepeatCount());
        }else{
            simpleScheduleBuilder = simpleScheduleBuilder.withRepeatCount(-1);
        }

        if(simpleTriggerBean.getMisfireInstruction() != null){
            if(simpleTriggerBean.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) {
                simpleScheduleBuilder = simpleScheduleBuilder.withMisfireHandlingInstructionIgnoreMisfires();
            }
            if(simpleTriggerBean.getMisfireInstruction() == SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW) {
                simpleScheduleBuilder = simpleScheduleBuilder.withMisfireHandlingInstructionFireNow();
            }
            if(simpleTriggerBean.getMisfireInstruction() == SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT) {
                simpleScheduleBuilder = simpleScheduleBuilder.withMisfireHandlingInstructionNextWithExistingCount();
            }
            if(simpleTriggerBean.getMisfireInstruction() == SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT) {
                simpleScheduleBuilder = simpleScheduleBuilder.withMisfireHandlingInstructionNextWithRemainingCount();
            }
            if(simpleTriggerBean.getMisfireInstruction() == SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT) {
                simpleScheduleBuilder = simpleScheduleBuilder.withMisfireHandlingInstructionNowWithExistingCount();
            }
            if(simpleTriggerBean.getMisfireInstruction() == SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT) {
                simpleScheduleBuilder = simpleScheduleBuilder.withMisfireHandlingInstructionNowWithRemainingCount();
            }
        }
        triggerBuilder = triggerBuilder.withSchedule(simpleScheduleBuilder);

        return (SimpleTrigger)triggerBuilder.build();
    }
}
 spring配置

 

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
       default-autowire="byName">
    <!--定时任务实现类-->
    <bean id="test1" class="com.jd.scheduling.quartz.test.Test1"/>
    <!--任务代理-->
    <bean id="jobDetail1" class="com.ab.scheduling.quartz.JobDetailProxyBean">
        <property name="targetObject" ref="test1"/>
        <property name="targetMethod" value="test"/>
    </bean>
    <!--触发器-->
    <bean id="cronTrigger" class="com.ab.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobDetail1"/>
        <property name="cronExpression" value="0/10 * * * * ?"/>
    </bean>
    <!--zk配置-->
    <bean id="zooKeeperFactory" class="com.ab.scheduling.quartz.ZookeeperFactory">
        <property name="hosts" value="127.0.0.1:2181"/>
        <property name="sessionTimeOut" value="15000"/>
        <property name="nameSpace" value="zk-scheduling"/>
    </bean>
    <!--调度工厂-->
    <bean id="schdulerFactory" autowire="no" class="com.ab.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="cronTrigger" />
            </list>
        </property>
        <property name="zooKeeperFactory" ref="zooKeeperFactory"/>
    </bean>
</beans>
 

 

 

  • 大小: 7.4 KB
分享到:
评论
2 楼 yakecjh 2017-11-06  
能否把代码提供出来下载看看
1 楼 biao6625133 2016-10-08  
你好!请问一下,JobDetailProxyBean这个类好像没有给出代码,这个类执行简单的对JobDetail封装而已吗?可以给出一下样例代码,学习下么???

相关推荐

    基于zookeeper临时顺序节点实现分布式调度

    在分布式系统中,调度是关键的一环,它涉及到任务的分配、执行以及资源的管理。在本场景中,我们利用Zookeeper...通过对这些文件的分析和理解,我们可以深入学习如何在实际项目中运用Zookeeper和Quartz实现分布式调度。

    基于Spring Boot和Quartz的分布式任务调度系统.zip

    基于Spring Boot和Quartz的分布式任务调度系统 项目简介 本项目是一个基于Spring Boot和Quartz框架的分布式任务调度系统,旨在提供一个灵活、可扩展的任务调度解决方案。系统支持多种任务类型,包括RPC任务、Cron...

    maven ssh+ quartz + zookeeper 实现分布式任务调度的管理界面

    在这个场景中,我们关注的是一个基于Maven、SSH(Spring、Struts2、Hibernate)框架、Quartz定时任务库以及Zookeeper协调服务的实现。这个系统提供了对分布式任务调度的管理界面,使得任务的创建、监控和管理变得...

    基于zookeeper+quartz/spring task的分布式任务调度组件,非常小巧,无需任何修改就可以使用

    【作品名称】:基于zookeeper+quartz/spring task的分布式任务调度组件,非常小巧,无需任何修改就可以使spring task具备分布式特性,确保所有任务在集群中不重复,不遗漏的执行。 【适用人群】:适用于希望学习...

    分布式定时任务调度系统技术选型指南.pdf

    通过将任务拆分成可并行执行的子任务,分布式定时任务可以在多节点上进行调度和执行,从而实现高可用和负载均衡。此外,它还提供了故障转移和任务恢复机制,确保任务的可靠执行。 2. **常见开源方案** - **Elastic...

    分布式定时任务调度系统技术选型指南.docx

    分布式定时任务是一种将原先分散、不可靠的计划任务整合到一个统一管理平台,并实现集群调度和分布式部署的技术。这种系统通过将任务切分成可分配的部分(分片),能够在多台机器上并行执行,提高效率,同时通过...

    基于java编写的分布式定时任务调度、管理、监控系统.zip

    在Java中,实现分布式定时任务调度最常用的框架是Quartz和Spring Scheduler。Quartz是一个开源的工作调度框架,支持复杂的调度逻辑和大规模的集群环境。Spring Scheduler则是Spring Framework的一部分,提供了与...

    Java 实现分布式定时任务

    总结,Java实现分布式定时任务涉及多个层面,包括选择合适的定时任务库、配置任务执行时间、处理分布式环境中的挑战以及选择适合的分布式调度解决方案。理解并熟练运用这些技术,可以帮助开发者构建出高效、稳定的...

    分布式任务调度框架 集合

    基于zookeeper+spring task的分布式任务调度组件,非常小巧,无需任何修改就可以使spring task具备分布式特性,确保所有任务在集群中不重复,不遗漏的执行。 5.Quartz 官方地址:...

    基于分布式锁或xxx-job实现分布式任务调度.zip

    这些框架提供了丰富的API和配置选项,用于定义、调度和监控任务。例如,XXL-JOB提供了Web界面进行任务管理和调度,同时支持简单任务、分布式任务以及复杂的调度策略。在SpringBoot项目中,可以通过引入相应的依赖并...

    Java分布式Elastic-Job和Quartz定时任务课程(1.6G)

    4_主流定时任务框架优缺点和什么是分布式定时任务.mp4 5_环境搭建总体流程.mp4 6_前期准备-JDK.mp4 7_前期准备-Maven.mp4 8_前期准备-MySQL.mp4 9_前期准备-Zookeeper.mp4 10_知识点检测与小结.mp4 11_Elastic-Job...

    Elastic-Job分布式任务调度视频教程

    有了任务调度即可解放更多的人力由系统自动去执行任务,Elastic-job是当当网基于quartz 二次开发的弹性分布式任务调度系统,功能丰富强大,采用zookeeper实现分布式协调,实现任务高可用以及分片。2、课程价值本着从...

    分布式定时任务ok

    "分布式定时任务OK"这个标题表明我们讨论的是一款能够顺利运行分布式定时任务的解决方案,它可能是一个框架或者一个工具,能够帮助开发者在微服务环境中实现高效、可靠的定时任务调度。 微服务架构是一种将单一应用...

    【Java毕业设计】挖坑,毕业后做了几年的任务调度,想聊聊分布式任务调度系统的设计与实现,打算先用 Java 写一版.zip

    - **ElasticJob**: 基于Apache ShenYu和Quartz,提供了分布式任务调度的解决方案,内置了故障转移和任务补偿功能。 - **Apache Airflow**: 虽然主要是Python库,但也有Java API,它强调工作流定义和可视化,适合...

    分布式调度任务架构elastic job的spring-boot-starter自动装载模块

    elastic job是当当网开源的基于quartz的分布式调度框架,通过zookeeper实 现分布式协调,加上支持分片、日志追踪、任务管理UI、高可性被大家熟知。 2.目前新的项目基本都是spring boot,如何通过约束、配置方式...

    分布式任务调度的解决方案.docx

    它利用ZooKeeper实现了任务的高可用性和分片处理,并支持云开发。 - **官方地址**:[ELASTIC-JOB](http://elasticjob.io/docs/elastic-job-lite/00-overview/) #### 方案对比 尽管XXL-JOB和ELASTIC-JOB都是优秀的...

    探寻繁杂定时任务的解决方案:分布式任务调度系统.docx

    面对这样的需求,企业急需一套一站式分布式调度任务解决方案,以统一管理这些繁杂的定时任务,从而增强其微服务平台的服务化能力和支撑云化服务转型。 #### 二、现有开源方案及其局限性 在分布式任务调度领域,...

    ElasticJob分布式调度解决方案.rar

    定时任务: 基于成熟的定时任务作业框架Quartz cron表达式执行定时任务。 作业注册中心: 基于Zookeeper和其客户端Curator实现的全局作业注册控制中心。用于注册,控制和协调分布式作业执行。 作业分片: 将一个...

    完美解决多应用服务器负载均衡环境下spring quartz同一定时任务重复执行问题

    Spring Quartz是一个强大的、开源的作业调度框架,允许开发者定义和执行复杂的定时任务。然而,当多个服务器实例并行运行时,如果不采取适当的策略,同一定时任务可能会在每个服务器上都执行,导致数据不一致和资源...

Global site tag (gtag.js) - Google Analytics