spring/springmvc/hibernate 配置异步线程池
2018-06-21 11:21
141 查看
版权声明:本人原创内容,希望大佬在转载时注明出处,感激不尽。 https://blog.csdn.net/qq_23832313/article/details/80757745
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<!-- 核心线程数 -->
<property name="corePoolSize" value="20" />
<!-- 最大线程数 -->
<property name="maxPoolSize" value="120" />
<!-- 队列最大长度 >=mainExecutor.maxSize -->
<property name="queueCapacity" value="120" />
<!-- 线程池维护线程所允许的空闲时间 -->
<property name="keepAliveSeconds" value="1000" />
<!-- 线程池对拒绝任务(无线程可用)的处理策略 ThreadPoolExecutor.CallerRunsPolicy策略 ,调用者的线程会执行该任务,如果执行器已关闭,则丢弃. -->
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
</property>
</bean>
最近在做一些调用python的工作,不需要接收python的返回值,因为调用比较耗时,所以这里采用异步线程的方式实现:
在 applicationContext.xml 里配置如下代码:
<!-- 异步线程池 -->
<bean id="threadPoolTaskExecutor"class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<!-- 核心线程数 -->
<property name="corePoolSize" value="20" />
<!-- 最大线程数 -->
<property name="maxPoolSize" value="120" />
<!-- 队列最大长度 >=mainExecutor.maxSize -->
<property name="queueCapacity" value="120" />
<!-- 线程池维护线程所允许的空闲时间 -->
<property name="keepAliveSeconds" value="1000" />
<!-- 线程池对拒绝任务(无线程可用)的处理策略 ThreadPoolExecutor.CallerRunsPolicy策略 ,调用者的线程会执行该任务,如果执行器已关闭,则丢弃. -->
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
</property>
</bean>
使用:
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
taskExecutor.execute(new Runnable() {
@Override
public void run() {
PythonInterfaceVisitUtil.callPython(params, pyProjectPath);
}
});
相关文章推荐
- spring+hibernate+mysql mvc 配置
- springMVC+hibernate+spring干净的一个配置文件
- WEB开发框架配置文件和各层注解(SpringMVC + Spring + Hibernate)
- 在spring-mvc.xml里配置异步
- springmvc + spring data jpa + hibernate 配置
- 将 Shiro 作为应用的权限基础 五:SpringMVC+Apache Shiro+JPA(hibernate)整合配置
- spring+springMVC+Hibernate全注解XML配置文件
- SpringMVC+Hibernate基本配置
- spring mvc+hibernate 实现事务管理(配置文件版)
- 在Spring3 MVC中五步配置集成注解方式Hibernate3
- spring mvc+hibernate 实现事务管理(配置文件版)
- Spring MVC+Spring+hibernate框架配置整合
- Spring + SpringMVC + Hibernate配置
- 将 Shiro 作为应用的权限基础 五:SpringMVC+Apache Shiro+JPA(hibernate)整合配置
- SpringMVC+Hibernate配置
- SpringMVC + hibernate 配置文件
- SpringMVC+Apache Shiro+JPA(hibernate)案例教学(一)整合配置
- springMVC+spring+hibernate配置
- SpringMVC+Apache Shiro+JPA(hibernate)案例教学(一)整合配置
- Spring+Hibernate+SpringMVC+MySql实现配置多个数据源!