日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

quartz定时定时任务执行两次

發布時間:2025/7/14 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 quartz定时定时任务执行两次 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

quartz框架沒問題。

流程:

sping-quartz配置

<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd "><context:annotation-config/><task:annotation-driven/><!-- 業務對象 --> <bean id="testJobTask" class="com.sunyard.quartz.TestQuartzTask" /><!-- 自動掃描包 --><context:component-scan base-package="com.sunyard.quartz.*" /><!-- 定時任務start --><!-- 調度業務 --> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><property name="targetObject" ref="testJobTask" /> <property name="targetMethod" value="execute" /> </bean><!-- 增加調用的觸發器,觸發時間 并注入到調度工廠--> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"><property name="jobDetail" ref="jobDetail" /> <property name="cronExpression" value="0/10 * * * * ? *" /> </bean><!-- 設置調度工廠 注入觸發器--><bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="cronTrigger" /></list></property></bean><!-- 定時任務end --></beans>

之后在web.xml中

<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mybatis.xml,classpath:spring-quartz.xml</param-value></context-param>

測試

/*** 定時任務--打印測試定時任務是否成功* @author wang**/ public class TestQuartzTask{public void execute() {System.out.println("定時任務已啟動!");} }

之后發現啟動之后輸出兩行,即任務啟動兩次。

最終解決:

<Host appBase="" autoDeploy="true" name="localhost" unpackWARs="true">

將appBase置空即可

轉載于:https://www.cnblogs.com/nankeyimengningchenlun/p/9641181.html

總結

以上是生活随笔為你收集整理的quartz定时定时任务执行两次的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。