堵塞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. Html静态网页下载—Teleport Pro 1.68 官方原版

    Teleport Pro 1.68 官方原版+有效注册码 – 下载整个网站 简介 Teleport Pro由美国Tennyson Maxwell公司开发,曾被PC Magazine评为”编辑选择奖”. ...

  2. dfs——皇后问题(回溯)

    #include <iostream> using namespace std; ],b[],c[],d[]; ; dfs(int i) { if(i>n) { sum++; ) { ...

  3. Java之从头开始编写简单课程信息管理系统

    编写简单的课程管理系统对于新手并不友好,想要出色的完成并不容易以下是我的一些经验和方法 详情可参考以下链接: https://www.cnblogs.com/dream0-0/p/10090828.h ...

  4. find 以及linux 和windows 文件互传

    1. find  命令  查找文件或目录 同时也会用到的有 which   whereis   locate   经常也会遇到一些快捷键  ctrl  +  l  e  a  w  u  k     ...

  5. [小A与最大子段和][斜率优化dp+二分]

    链接:https://ac.nowcoder.com/acm/contest/545/A来源:牛客网题目描述 小A在网上看到了 "最大子段和" 问题的解法.第二天,小A向小B讲解了 ...

  6. python------面向对象介绍之多态实例

    一. 多态 一种接口,多种实现. 多态性(polymorphisn)是允许你将父对象设置成为和一个或更多的他的子对象相等的技术,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作. ...

  7. 原版win10

    windows10专业版:ed2k://|file|cn_windows_10_multiple_editions_x64_dvd_6848463.iso|4303300608|94FD861E824 ...

  8. IDEA在jsp页面写out.print()代码报错

    如题,小编以前用myeclipse,eclipse的时候,在jsp里写java代码都是可以的,现在我换成了IDEA,却莫名报错 而且没有代码提示,比如说下图这样的,,虽然运行还是能运行...但对强迫症 ...

  9. Cassandra Demo--Python操作cassandra

    ================================================================ 创建keyspace和table CREATE KEYSPACE ex ...

  10. hive array、map、struct使用

    hive提供了复合数据类型:Structs: structs内部的数据可以通过DOT(.)来存取,例如,表中一列c的类型为STRUCT{a INT; b INT},我们可以通过c.a来访问域aMaps ...