實現定時任務的執行,而且要求定時周期是不固定的。測試地址: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>