zoukankan      html  css  js  c++  java
  • spring4 quartz2 集群动态任务

    实现定时任务的执行,而且要求定时周期是不固定的。测试地址:http://sms.reyo.cn

    生产环境:nginx+tomcat+quartz2.2.1+spring4.2.1 集群。

    实现功能:可添加新任务,删除任务,更新任务,暂停任务,恢复任务

    任务管理:

    修改任务:

    新增任务:

    静态任务实现每20秒websocket向客户端发送一文字消息和图片信息。

    静态任务测试地址(刷新地址可以看到访问到不同的服务器):http://sms.reyo.cn/socket.html    

    以下是静态任务配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    
        <!-- 启动触发器的配置开始 -->
        <bean name="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref bean="autoBatchTestTrigger" />
                    <!-- <ref bean="cleanErrorTaskTrigger"/> -->
                </list>
            </property>
            <property name="schedulerName"><value>first</value></property> 
        </bean>
        <!-- 启动触发器的配置结束 -->
    
        <!-- 自动测试任务的配置 -->
        <bean id="autoBatchTestTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
            <property name="jobDetail">
                <ref bean="autoBatchTestJobDetail" />
            </property>
            <property name="cronExpression">
                <value>*/20 * * * * ?</value>
            </property>
    
        </bean>
        <!-- 调度的配置结束 -->
    
        <!-- job的配置开始 -->
        <bean id="autoBatchTestJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject">
                <ref bean="autoBatchTestJob" />
            </property>
            <property name="targetMethod">
                <value>autoBatchTestTask</value>
            </property>
        </bean>
        <!-- job的配置结束 -->
    
        <!-- 工作的bean -->
        <bean id="autoBatchTestJob" class="reyo.sdk.websocket.quartz.QuartzTaskManager" />
        <!-- 自动测试任务结束 -->
    
    </beans>
  • 相关阅读:
    python3 访问 rabbitmq 示例
    centos7 GNOME 安装微信客户端
    使用 rm -rf 删除了工程目录,然后从 pycharm 中找了回来
    主动做事,做一个靠谱的人
    Go net/http 发送常见的 http 请求
    学会感激,才能长大
    Go context 介绍和使用
    xargs 命令
    Docker 镜像 && 容器的基本操作
    CentOS && Ubuntu 环境下 Docker 的安装配置
  • 原文地址:https://www.cnblogs.com/interdrp/p/4851500.html
Copyright © 2011-2022 走看看