applicationContext-threadpool.xml 1.7 KB

1234567891011121314151617181920212223242526
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  5. <!-- 线程池配置 -->
  6. <bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
  7. <!-- 线程池维护线程的最少数量 -->
  8. <property name="corePoolSize" value="50" />
  9. <!-- 线程池维护线程的最大数量,默认为Integer.MAX_VALUE -->
  10. <property name="maxPoolSize" value="1000" />
  11. <!-- 线程池所使用的缓冲队列,一般需要设置值>=notifyScheduledMainExecutor.maxNum;默认为Integer.MAX_VALUE -->
  12. <property name="queueCapacity" value="20000" />
  13. <!-- 线程池维护线程所允许的空闲时间,默认为60s -->
  14. <property name="keepAliveSeconds" value="300" />
  15. <!-- 线程池对拒绝任务(无线程可用)的处理策略,目前只支持AbortPolicy、CallerRunsPolicy;默认为后者 -->
  16. <property name="rejectedExecutionHandler">
  17. <!-- AbortPolicy:直接抛出java.util.concurrent.RejectedExecutionException异常 -->
  18. <!-- CallerRunsPolicy:主线程直接执行该任务,执行完之后尝试添加下一个任务到线程池中,可以有效降低向线程池内添加任务的速度 -->
  19. <!-- DiscardOldestPolicy:抛弃旧的任务、暂不支持;会导致被丢弃的任务无法再次被执行 -->
  20. <!-- DiscardPolicy:抛弃当前任务、暂不支持;会导致被丢弃的任务无法再次被执行 -->
  21. <bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
  22. </property>
  23. </bean>
  24. </beans>