【转】non-blocking REST services with Spring MVC
堵塞Controller
- Controller为单例;
- 非线程安全;
- 堵塞方式;
- 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的更多相关文章
- CRUD using Spring MVC 4.0 RESTful Web Services and AngularJS
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 深入分析Spring 与 Spring MVC容器
1 Spring MVC WEB配置 Spring Framework本身没有Web功能,Spring MVC使用WebApplicationContext类扩展ApplicationContext, ...
- spring mvc DispatcherServlet详解之前传---FrameworkServlet
做项目时碰到Controller不能使用aop进行拦截,从网上搜索得知:使用spring mvc 启动了两个context:applicationContext 和WebapplicationCont ...
- Spring MVC 学习 -- 创建过程
Spring MVC 学习 -- 创建过程 Spring MVC我们使用的时候会在web.xml中配置 <servlet> <servlet-name>SpringMVC< ...
- Spring MVC和CXF集成
前提: 1.spring mvc环境已搭建好,能跑起来. 2.下载apache-cxf-2.7.3.zip的压缩包,解压apache-cxf-2.7.3.zip压缩包,拷贝如下几个jar包即可. 配置 ...
- springboot Serving Web Content with Spring MVC
Serving Web Content with Spring MVC This guide walks you through the process of creating a "hel ...
- spring MVC、mybatis配置读写分离
spring MVC.mybatis配置读写分离 1.环境: 3台数据库机器,一个master,二台slave,分别为slave1,slave2 2.要实现的目标: ①使数据写入到master ②读数 ...
- Spring MVC 学习总结(六)——Spring+Spring MVC+MyBatis框架集成
与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...
- Spring MVC 学习总结(五)——校验与文件上传
Spring MVC不仅是在架构上改变了项目,使代码变得可复用.可维护与可扩展,其实在功能上也加强了不少. 验证与文件上传是许多项目中不可缺少的一部分.在项目中验证非常重要,首先是安全性考虑,如防止注 ...
随机推荐
- 微信导出群记录V3.0
一.序 导出东北师范大学2017级软件工程微信群的聊天记录,形式不限,但需要包含文字.图片和链接,不允许截图. 聊天记录的时间段为2017年11月3日12:00起至2018年1月3日12:00. 二. ...
- PTA——数列求和
PTA 7-34 求分数序列前N项和 #include<stdio.h> int main() { int i,n; ,fm = ,sum = ; scanf("%d" ...
- js中将一个字一个字的打印出来
第一种方式: setTimeout(function(){ var cc=document.createTextNode(ss[i]) content.appendChild(cc) },3000)
- Ubuntu下一个好用的终端
在终端下输入: sudo apt-get install terminator 快捷键: shift+ctrl+e 在当前窗口右侧新开一个窗口 shift+ctrl+w ...
- maven settings.xml配置优化
<?xml version="1.0" encoding="UTF-8"?> <settings> <localRepositor ...
- 每天进步一点点-序列化和反序列(将对象写入硬盘文件and从硬盘文件读出对象)
一个类如果实现了Serializable接口,那么这个类创建的对象就是所谓序列化的对象.所谓“对象序列化”: 简单一句话:使用它可以象存储文本或者数字一样简单的存储对象.一个应用是,程序在执行过程中突 ...
- python基础(三)——类的研究
class Employee: //定义类 以冒号结束 '所有员工的基类' //帮助信息 empCount = 0 def __init__(self, name, salary): //调用时初始化 ...
- GraphQL Gateway Architectures
转自: https://tomasalabes.me/blog/graphql/node/microservices/2018/08/11/graphql-architectures.html Gra ...
- Kafka 文件存储机制那些事 - 美团技术团队
出处:https://tech.meituan.com/2015/01/13/kafka-fs-design-theory.html 自己总结: Kafka 文件存储机制_结构图:https://ww ...
- MySQL 中,\g和\G的作用
MySQL 中,\g和\G的作用: \g 的作用是 go (\g) Send command to mysql server. \G 的作用是将查询到的结果,每行显示一个字段和字段值,方便查看 ego ...