作者:bakurei_492 | 来源:互联网 | 2023-09-08 10:25
实现定时任务的执行,而且要求定时周期是不固定的。测试地址:http://sms.reyo.cn
生产环境:nginx+tomcat+quartz2.2.1+spring4.2.1 集群。
实现功能:可添加新任务,删除任务,更新任务,暂停任务,恢复任务
任务管理:
![spring4 quartz2 集群动态任务 spring4 quartz2 集群动态任务](https://img1.php1.cn/3cd4a/250c2/807/8c8e6b694cdac44b.png)
![spring4 quartz2 集群动态任务 spring4 quartz2 集群动态任务](https://img1.php1.cn/3cd4a/250c2/807/fce9fcf42b7248a6.png)
修改任务:
![spring4 quartz2 集群动态任务 spring4 quartz2 集群动态任务](https://img1.php1.cn/3cd4a/250c2/807/da7c9cebe71a57e7.png)
新增任务:
![spring4 quartz2 集群动态任务 spring4 quartz2 集群动态任务](https://img1.php1.cn/3cd4a/250c2/807/4402acb15b357303.png)
![spring4 quartz2 集群动态任务 spring4 quartz2 集群动态任务](https://img1.php1.cn/3cd4a/250c2/807/1fe2e01d7cb980de.png)
静态任务实现每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" />
list>
property>
<property name="schedulerName"><value>firstvalue>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>
<bean id="autoBatchTestJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="autoBatchTestJob" />
property>
<property name="targetMethod">
<value>autoBatchTestTaskvalue>
property>
bean>
<bean id="autoBatchTestJob" class="reyo.sdk.websocket.quartz.QuartzTaskManager" />
beans>