<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <property name="corePoolSize" value="5" /> <property name="maxPoolSize" value="10" /> <!-- 缓存队列 --> <property name="queueCapacity" value="20" /> <!-- 线程池维护线程所容许的空闲时间 --> <property name="keepAliveSeconds" value="300" /> <!-- 对拒绝task的处理策略 --> <property name="rejectedExecutionHandler"> <bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" /> </property> <property name="WaitForTasksToCompleteOnShutdown" value="true" /> </bean>
@Autowired private ThreadPoolTaskExecutor taskExecutor;