旅行社网站程序,兼职 网站 小程序 建设,怎么修改地图的公司地址,网站切版教程关于Spring 任务调度之task:scheduler与task:executor配置的详解
其实就是Spring定时器中配置文件中一些配置信息#xff0c;由于笔者自己是头一次使用#xff0c;有些配置详细不太明白#xff0c;随即研究了一番#xff0c;于是想记录一下#xff0c;有需要的小伙伴可以…关于Spring 任务调度之task:scheduler与task:executor配置的详解
其实就是Spring定时器中配置文件中一些配置信息由于笔者自己是头一次使用有些配置详细不太明白随即研究了一番于是想记录一下有需要的小伙伴可以参考也方便日后自己查阅。 首先创建一个仅仅包含定时器配置的Spring配置文件spring-timer.xml。以下均为配置信息 1、在配置文件头部加入定时器的命名空间----------
?xml version1.0 encodingUTF-8?
beans
xmlnshttp://www.springframework.org/schema/beans
xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance
xmlns:phttp://www.springframework.org/schema/p
xmlns:contexthttp://www.springframework.org/schema/context
xmlns:aophttp://www.springframework.org/schema/aop
xmlns:taskhttp://www.springframework.org/schema/task
xsi:schemaLocationhttp://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/beans2、定时器的详细配置---------- 注解方式
context:annotation-config /!-- 自动调度需要扫描的包 -- context:component-scan base-packagecom.honest.sspc.timer /context:component-scan!-- 定时器开关 --task:executor idexecutor pool-size5/task:scheduler idscheduler pool-size10/task:annotation-driven executorexecutor schedulerscheduler/xml配置方式
context:annotation-config /!-- 自动调度需要扫描的包 -- context:component-scan base-packagecom.honest.sspc.timer /context:component-scan!-- 定时器开关 --task:executor idexecutor pool-size5/ task:annotation-driven executorexecutor schedulerscheduler/ !-- 配置调度 需要在类名前添加 Service -- task:scheduled-tasks task:scheduled refdemoTask methodmyTestWork cron0/10 * * * * ?/ /task:scheduled-tasks task:scheduler idscheduler pool-size10/!-- 不通过配置调度,需要在类名前 Component/Service,在方法名 前添加Scheduled(cron0/5 * * * * ? )、即用注解的方式-- 3、关于任务调度的说明---------- 任务调度器的配置详细参数说明 task:scheduler/pool-size调度线程池的大小调度线程在被调度任务完成前不会空闲 task:scheduled/croncron表达式注意若上次任务未完成即使到了下一次调度时间任务也不会重复调度
task:scheduled-tasks schedulerscheduler task:scheduled refbeanID methodmethodName cronCronExp /
/task:scheduled-tasks
task:scheduler idscheduler pool-size1 /任务执行器配置详细参数说明 task:executor/pool-size可以指定执行线程池的初始大小、最大大小 task:executor/queue-capacity等待执行的任务队列的容量 task:executor/rejection-policy当等待队列爆了时的策略分为丢弃、由任务执行器直接运行等方式
task:executor idexecutor keep-alive3600 pool-size100-200 queue-capacity500 rejection-policyCALLER_RUNS /