<!-- 任务从此处开始加载 -->
<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