spring中异步配置

来源:互联网 发布:五级三晋制工资算法 编辑:程序博客网 时间:2024/06/05 05:17

在平时开发中,有一些相对耗时操作需要使用异步处理,Spring中已经帮我们集成好了,在类中注入TaskExecutor即可,调用execute方法。配置如下


<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"><property name="corePoolSize" value="4" /> <!-- 并发线程数,想达到真正的并发效果,最好对应CPU的线程数及核心数 --><property name="maxPoolSize" value="10" /> <!-- 最大线程池容量 --><property name="queueCapacity" value="4000" /> <!-- 超过最大线程池容量后,允许的线程队列数 --><property name="keepAliveSeconds" value="30" /> <!-- 线程池维护线程所允许的空闲时间 --><property name="allowCoreThreadTimeOut" value="true"></property> <!-- 空闲的时候让线程等待keepAliveTime,timeout后使得poolSize能够降为0 --></bean>

原创粉丝点击