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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

关于Spring 任务调度之task:scheduler与task:executor配置的详解

發布時間:2025/3/12 javascript 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于Spring 任务调度之task:scheduler与task:executor配置的详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

關于Spring 任務調度之task:scheduler與task:executor配置的詳解

其實就是Spring定時器中配置文件中一些配置信息,由于筆者自己是頭一次使用,有些配置詳細不太明白,隨即研究了一番,于是想記錄一下,有需要的小伙伴可以參考,也方便日后自己查閱。
首先,創建一個僅僅包含定時器配置的Spring配置文件:spring-timer.xml。以下均為配置信息:
1、在配置文件頭部加入定時器的命名空間----------

<?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:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task" 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/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"></beans>

2、定時器的詳細配置----------
注解方式:

<context:annotation-config /><!-- 自動調度需要掃描的包 --> <context:component-scan base-package="com.honest.sspc.timer" ></context:component-scan><!-- 定時器開關 --><task:executor id="executor" pool-size="5"/><task:scheduler id="scheduler" pool-size="10"/><task:annotation-driven executor="executor" scheduler="scheduler"/>

xml配置方式:

<context:annotation-config /><!-- 自動調度需要掃描的包 --> <context:component-scan base-package="com.honest.sspc.timer" ></context:component-scan><!-- 定時器開關 --><task:executor id="executor" pool-size="5"/> <task:annotation-driven executor="executor" scheduler="scheduler"/> <!-- 配置調度 需要在類名前添加 @Service --> <task:scheduled-tasks> <task:scheduled ref="demoTask" method="myTestWork" cron="0/10 * * * * ?"/> </task:scheduled-tasks> <task:scheduler id="scheduler" pool-size="10"/><!-- 不通過配置調度,需要在類名前 @Component/@Service,在方法名 前添加@Scheduled(cron="0/5 * * * * ? ")、即用注解的方式-->

3、關于任務調度的說明----------
任務調度器的配置詳細參數說明:
task:scheduler/@pool-size:調度線程池的大小,調度線程在被調度任務完成前不會空閑
task:scheduled/@cron:cron表達式,注意,若上次任務未完成,即使到了下一次調度時間,任務也不會重復調度

<task:scheduled-tasks scheduler="scheduler"> <task:scheduled ref="beanID" method="methodName" cron="CronExp" /> </task:scheduled-tasks> <task:scheduler id="scheduler" pool-size="1" />

任務執行器配置詳細參數說明:
task:executor/@pool-size:可以指定執行線程池的初始大小、最大大小
task:executor/@queue-capacity:等待執行的任務隊列的容量
task:executor/@rejection-policy:當等待隊列爆了時的策略,分為丟棄、由任務執行器直接運行等方式

<task:executor id="executor" keep-alive="3600" pool-size="100-200" queue-capacity="500" rejection-policy="CALLER_RUNS" />

總結

以上是生活随笔為你收集整理的关于Spring 任务调度之task:scheduler与task:executor配置的详解的全部內容,希望文章能夠幫你解決所遇到的問題。

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