quartz定時任務實現只執行一次,以後不再執行

2021-08-20 17:14:19 字數 1679 閱讀 5729

按說只在tomcat啟動時執行一次,我們可以用***來實現,但是有些開發框架中因特殊場景不適合用***。那麼定時任務也可以實現只執行一次的操作。配置如下

好使的話大家給個贊

<?

xml version

="1.0"

encoding

="utf-8"

?>

xmlns

=""xmlns:

mvc=""

xmlns:

xsi=""

xmlns:

context

=""

xmlns:

tx=""

xmlns:

util

=""xsi:schemalocation

=" /spring-beans-4.0.xsd

/spring-mvc-4.0.xsd

/spring-tx-4.0.xsd

/spring-context-4.0.xsd

/spring-util-4.0.xsd"

>

id="publicwebservicejob"

class

="cn.org.site.business.quartz.publicwebserviceschedulejob"

/>

id="publicwebservicejobdetail"

class

="org.springframework.scheduling.quartz.methodinvokingjobdetailfactorybean"

>

name

="targetobject"

ref="publicwebservicejob"

/>

name

="targetmethod"

value

="dojob"

>

name

="concurrent"

value

="false"

/>

id="publicwebservicetriggerbean"

class

="org.springframework.scheduling.quartz.******trigge***ctorybean"

>

name

="jobdetail"

ref="publicwebservicejobdetail"

/>

name

="startdelay"

value

="5000"

/>

name

="repeatcount"

value

="0"

/>

id="schedule***ctorybean-em"

lazy-init

="false"

class

="org.springframework.scheduling.quartz.schedule***ctorybean"

>

name

="triggers"

>

bean

="publicwebservicetriggerbean"

/>

Quartz 實現定時任務

1 引用quartz依賴 org.quartz scheduler quartz 2.3.2 2 實現具體的可執行的排程任務類,排程任務類需實現quartz框架提供的job介面。override public void execute jobexecutioncontext jobexecution...

spring boot 定時任務實現

scheduled 使用 scheduled 非常容易,直接建立乙個 spring boot 專案,並且新增 web 依賴 spring boot starter web,專案建立成功後,新增 enablescheduling 註解,開啟定時任務 enablescheduling 開啟定時任務 pu...

Spring定時任務實現

一 spring 定時任務 component enablescheduling 可以在啟動類上註解也可以在當前檔案 public class testschedule scheduled fixedrate 1000 10 public void runsecend scheduled fixed...