<!-- 任务从此处开始加载 -->
<bean id="notifySpringScheduledExecutorFactoryBean" class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean">
<property name="scheduledExecutorTasks">
<list>
<ref bean="notifySpringScheduledExecutorTask" />
</list>
</property>
</bean>
<!-- 待加入Spring Schedual进行调度的task列表 -->
<bean id="notifySpringScheduledExecutorTask" class="org.springframework.scheduling.concurrent.ScheduledExecutorTask">
<property name="runnable" ref="notifyScheduledMainExecutor" />
<!-- 初次执行任务delay时间,单位为ms,默认值为0,代表首次加载任务时立即执行;比如1min -->
<property name="delay" value="60000" />
<!-- 间隔时间,单位为ms,默认值为0,代表任务只执行一次;比如2min -->
<property name="period" value="120000" />
<!-- 是否采用fixedRate方式进行任务调度,默认为false,即采用fixedDelay方式 -->
<!-- fixedRate:定时间隔执行,不管上次任务是否已执行完毕;fixedDelay:每次任务执行完毕之后delay固定的时间 -->
<property name="fixedRate" value="true" />
</bean>
<!-- 任务调度主线程 -->
<bean id="notifyScheduledMainExecutor" class="com.alisoft.aep.notify.schedual.NotifyScheduledMainExecutor">
<!-- 针对Notify服务端的Service,用于更新Notify重试信息等 -->
<property name="notifyServerService" ref="notifyServerService" />
<!-- notify.notifyId缓存策略实现类,可自行扩展 -->
<property name="notifyIdCacheStrategy" ref="defaultNotifyIdCacheStrategy" />
<!-- notify.load_balance_num字段值生成、以及调度时where条件中取值的策略实现类,可自行扩展 -->
<!-- 当有多台notify服务器时才有用,用于平衡各台server间的压力;一般不用配置 -->
<!-- <property name="loadBalanceNumStrategy" ref="alternateLoadBalanceNumStrategy" /> -->
<!-- notify.handler字段值在调度时where条件中取值的策略实现类,可自行扩展 -->
<!-- 当有多台notify服务器时才有用,用于表明某台server可执行哪些handler;一般不用配置 -->
<!-- <property name="notifyHandlerStrategy" ref="defaultNotifyHandlerStrategy" /> -->
<!-- 当有多台notify服务器时才有用,用于设置某台server调度时每次读取的Notify最大数,用于覆盖maxNum;一般不用配置 -->
<!-- <property name="notifyMaxNumPerJobStrategy" ref="defaultNotifyMaxNumPerJobStrategy" /> -->
<!-- 用于并发的线程池 -->
<property name="notifyTaskExecutor" ref="notifyTaskExecutor" />
<!-- 每次调度读取的Notify最大记录数,默认为1000 -->
<property name="maxNum" value="1000" />
<property name="notifyDao" ref="notifyDao" />
</bean>
<!-- 异步线程池 -->
<bean id="notifyTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<!-- 核心线程数,默认为1 -->
<property name="corePoolSize" value="10" />
<!-- 最大线程数,默认为Integer.MAX_VALUE -->
<property name="maxPoolSize" value="50" />
<!-- 队列最大长度,一般需要设置值>=notifyScheduledMainExecutor.maxNum;默认为Integer.MAX_VALUE -->
<property name="queueCapacity" value="1000" />
<!-- 线程池维护线程所允许的空闲时间,默认为60s -->
<property name="keepAliveSeconds" value="300" />
<!-- 线程池对拒绝任务(无线程可用)的处理策略,目前只支持AbortPolicy、CallerRunsPolicy;默认为后者 -->
<property name="rejectedExecutionHandler">
<!-- AbortPolicy:直接抛出java.util.concurrent.RejectedExecutionException异常 -->
<!-- CallerRunsPolicy:主线程直接执行该任务,执行完之后尝试添加下一个任务到线程池中,可以有效降低向线程池内添加任务的速度 -->
<!-- DiscardOldestPolicy:抛弃旧的任务、暂不支持;会导致被丢弃的任务无法再次被执行 -->
<!-- DiscardPolicy:抛弃当前任务、暂不支持;会导致被丢弃的任务无法再次被执行 -->
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
</property>
</bean>
<bean id="notifyServerService" class="com.alisoft.aep.notify.service.impl.NotifyServerServiceImpl">
<!-- 针对任务执行失败后Notify如何重试的策略实现类,可自行扩展 -->
<property name="notifyRetryStrategy" ref="defaultNotifyRetryStrategy" />
<!-- 针对任务执行失败后异常处理策略实现类,可自行扩展 -->
<!-- 默认不对异常进行补救,具体handler实现类中若返回NULL或抛出异常,则均按异常处理,直接将Notify记录迁移到历史表中,不进行重试; -->
<!-- <property name="notifyHandlerExceptionStrategy" ref="defaultNotifyHandlerExceptionStrategy" /> -->
<!-- 描述见notifyScheduledMainExecutor -->
<property name="notifyIdCacheStrategy" ref="defaultNotifyIdCacheStrategy" />
<!-- 事务模板,需保证能够找到对应的bean -->
<property name="transactionTemplate" ref="transactionTemplate" />
<property name="notifyDao" ref="notifyDao" />
</bean>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sfdev/archive/2009/04/08/4056114.aspx
分享到:
相关推荐
spring 任务调度实现代码例子
NULL 博文链接:https://weiweichen1985.iteye.com/blog/1006969
spring任务调度(Quartz )非常基础,
java spring任务调度器
Spring任务调度的几种实现方法,包括持续运行某个方法,固定某个时间点运行
maven spring 任务调度实列代码
Spring 定时器 任务调度 怎么在项目中写定时任务 怎么配置一些环境
Spring实现任务调度.ppt Spring实现任务调度_代码演示 quartz-all-1.6.1.jar
Spring实现任务调度.ppt Spring实现任务调度_代码演示 quartz-all-1.6.1.jar
Spring任务调度ppt,讲的很细和值得看一下。
springtask配置,大家一起参考学习下,分享下。Java方面
Spring 任务调度
该资源描述了用spring+quartz搭建的环境来管理任务调度的基本配置
Spring整合任务调度框架Quartz,本文档详细介绍了Spring整合任务调度框架Quartz,希望可以帮助学习者
关于spring调度的例子;| 两种方法:quartz 和 timer;| 适合学习;| 已经调试通过
关于spring 的 quartz 的入门练习 讲解比较详细,自己做过的例子,3分绝对值了
Spring任务
Spring定时任务的几种实现,欢迎交流!
spring2.5 定时器任务 spring2.5 定时器任务 spring2.5 定时器任务 spring2.5 定时器任务