堵塞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. opencv中mat类介绍

    The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It ...

  2. hdu 1556 A - Color the ball 数状数组做法

    #include<bits/stdc++.h> using namespace std; ; int n; int c[maxn]; int lowbit(int x) { return ...

  3. 浅谈log4j-5-读取properties文件(转自godtrue)

    #### 在代码中配置log4j环境的方式,我们已经见识过了,是不是感觉比较麻烦,我们试试使用配置文件的方式是否使您的应用程序更加的灵活.# Log4j支持两种配置文件格式,一种是XML格式的文件,一 ...

  4. SVN三种合并类型

    https://blog.csdn.net/zht666/article/details/36178117 转自:http://wenku.baidu.com/link?url=pnALYESJnX0 ...

  5. photoshop 笔记

    替换颜色 (图像)—(调整)—(替换颜色)—点下你想换掉的绿色----拖动下方的滑 块—(色相)拖到最大—(饱合度)调到最小----(明度)调到最大 OK 发现对你不想变色的图像稍微有点影响,但只是一 ...

  6. Eclipse工具的设置

    1 Eclipse的工作空间和新建工程1.1: 工作空间* 其实就是我们写的源代码所在的目录 1.2: 创建工程(项目)* 右键/Package Explore 空白区/new /Java Proje ...

  7. Ts基础

    //typeof 用来判断变量类型 var s: string = 'egret'; var isString: boolean = typeof s === 'string'; console.lo ...

  8. python 简明教程 【转】

    转自:https://learnxinyminutes.com/docs/python/ # Single line comments start with a number symbol. &quo ...

  9. js 判断滚动条是否停止滚动

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. centos7 虚拟机安装 以后不能联网问题

    1 设置 网络模式为桥接. 2 配置/etx/sysconfig/network-scrips/ifcfg-enthp0s3为如下配置( ip 网段 根据自己网段决定) TYPE=Ethernet P ...