`
Franciswmf
  • 浏览: 780356 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

Spring MVC的异步模式

 
阅读更多
引用参考
1、高性能的关键:Spring MVC的异步模式
https://www.cnblogs.com/winner-0715/p/5759432.html
2、Spring MVC 异步处理请求,提高程序性能
https://blog.csdn.net/he90227/article/details/52262163
3、springMVC整合异步请求特性
https://blog.csdn.net/u013755987/article/details/62424001

xml配置
<!-- 异步任务线程池 -->
	<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
	   <!-- 核心线程数 -->
	   <property name="corePoolSize" value="5"></property>
	   <!-- 最大线程数 -->
	   <property name="maxPoolSize" value="50"></property>
	   <!-- 队列容量 -->
	   <property name="queueCapacity" value="20"></property>
	   <!-- 线程池维护线程所允许的空闲时间 -->
       <property name="keepAliveSeconds" value="1000" />
       <!-- 线程池对被拒绝(无线程可用)任务的处理策略 ThreadPoolExecutor.CallerRunsPolicy策略 ,调用者的线程会执行该任务,如果执行器已关闭,则丢弃  -->
       <property name="rejectedExecutionHandler">
       		<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
       </property>
	</bean>


controller里面:
    @Autowired
    @Qualifier("threadPoolTaskExecutor")
    private AsyncTaskExecutor asyncTaskExecutor;
//...
Callable<String> callableTask= new Callable<String>() {
            @Override
            public String call() throws Exception {
                //add code here
            }
        };
        return new WebAsyncTask<String>(30000L, asyncTaskExecutor, callableTask);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics