堵塞Controller

  1. Controller为单例;
  2. 非线程安全;
  3. 堵塞方式;
  4. 1个request对应1个处理Thread;
@RestController
public class ProcessingController { @RequestMapping("/process-blocking")
public ProcessingStatus blockingProcessing(...) {
...
return new ProcessingStatus(...);
}
}

非阻塞

@RestController
public class ProcessingController { @RequestMapping("/process-non-blocking")
public DeferredResult<ProcessingStatus> nonBlockingProcessing(...) { // Initiate the processing in another thread
DeferredResult<ProcessingStatus> deferredResult = new DeferredResult<>();
ProcessingTask task = new ProcessingTask(deferredResult, ...);
dispatch(task); // Return to let go of the precious thread we are holding on to...
return deferredResult;
}
} public class ProcessingTask extends SomeCallbackInterface { private DeferredResult<ProcessingStatus> deferredResult; public ProcessingTask(DeferredResult<ProcessingStatus> deferredResult, ...) {
this.deferredResult = deferredResult;
...
} @Override
public void done() {
if (deferredResult.isSetOrExpired()) {
LOG.warn("Processing of non-blocking request already expired");
} else {
boolean deferredStatus = deferredResult.setResult(new ProcessingStatus(...));
}
}
}


原文链接

Developing non-blocking REST services with Spring MVC

【转】non-blocking REST services with Spring MVC的更多相关文章

  1. CRUD using Spring MVC 4.0 RESTful Web Services and AngularJS

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  2. 深入分析Spring 与 Spring MVC容器

    1 Spring MVC WEB配置 Spring Framework本身没有Web功能,Spring MVC使用WebApplicationContext类扩展ApplicationContext, ...

  3. spring mvc DispatcherServlet详解之前传---FrameworkServlet

    做项目时碰到Controller不能使用aop进行拦截,从网上搜索得知:使用spring mvc 启动了两个context:applicationContext 和WebapplicationCont ...

  4. Spring MVC 学习 -- 创建过程

    Spring MVC 学习 -- 创建过程 Spring MVC我们使用的时候会在web.xml中配置 <servlet> <servlet-name>SpringMVC< ...

  5. Spring MVC和CXF集成

    前提: 1.spring mvc环境已搭建好,能跑起来. 2.下载apache-cxf-2.7.3.zip的压缩包,解压apache-cxf-2.7.3.zip压缩包,拷贝如下几个jar包即可. 配置 ...

  6. springboot Serving Web Content with Spring MVC

    Serving Web Content with Spring MVC This guide walks you through the process of creating a "hel ...

  7. spring MVC、mybatis配置读写分离

    spring MVC.mybatis配置读写分离 1.环境: 3台数据库机器,一个master,二台slave,分别为slave1,slave2 2.要实现的目标: ①使数据写入到master ②读数 ...

  8. Spring MVC 学习总结(六)——Spring+Spring MVC+MyBatis框架集成

    与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...

  9. Spring MVC 学习总结(五)——校验与文件上传

    Spring MVC不仅是在架构上改变了项目,使代码变得可复用.可维护与可扩展,其实在功能上也加强了不少. 验证与文件上传是许多项目中不可缺少的一部分.在项目中验证非常重要,首先是安全性考虑,如防止注 ...

随机推荐

  1. Unity3D 重写下拉菜单/Dropdown组件、开启每个按钮可用

    Override Dropdown Component 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) ...

  2. Gym.101908 Brazil Subregional Programming Contest(寒假自训第六场)

    这几天睡眠时间都不太够,室友晚上太会折腾了,感觉有点累,所以昨天的题解也没写,看晚上能不能补起来. B . Marbles 题意:给定N组数(xi,yi),玩家轮流操作,每次玩家可以选择其中一组对其操 ...

  3. lesson3 overfitting -fastai

    VGG:3*3Imagenet:7*7,9*9论文中证明3*3更胜一筹,但是用多少并没有定论微调:删掉模型的中间只对最后一层微调:model.pop,就删掉了最后一层 如何决定训练多少层?:·看论文上 ...

  4. 基础练习 2n皇后问题

    时间限制:1.0s 内存限制:512.0MB 提交此题 锦囊1 锦囊2 问题描述 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同 ...

  5. 快速排序 C语言实现

    转载于> http://blog.chinaunix.net/uid-26404477-id-3329885.html 总的关键字比较次数:O(nlgn) 尽管快速排序的最坏时间为O(n2),但 ...

  6. scrapy框架学习之路

    一.基础学习 - scrapy框架 介绍:大而全的爬虫组件. 安装: - Win: 下载:http://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted pip3 ...

  7. acm 2001

    格式化输出 //////////////////////////////////////////////////////////////////////////////// #include<i ...

  8. 《DSP using MATLAB》Problem 5.38

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  9. Map 按Key排序 和 按Value排序

    https://www.cnblogs.com/binz/p/6671917.html 一.根据value排序 通用方法 public class MapUtil { public static &l ...

  10. 【HAOI2011】 向量

    数论好劲啊 原题: 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出 ...