堵塞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

最新文章

  1. Redis时延问题分析及应对
  2. jquery的show/hide/toggle详解
  3. 记一次Redis和NetMQ的测试
  4. iOS搜索附近的位置(类似微博朋友圈位置)
  5. Eclipse中Java项目转换为Web项目
  6. md5sum 生成 经md5加密后的字符串
  7. 《java笔记 day07》
  8. magiczoom 插件去版本(放大镜效果)
  9. python 多行字符串
  10. 通过live555实现H264 RTSP直播
  11. java mysql驱动
  12. 测试体验Centrifugo
  13. NIO学习
  14. Asp.Net SignalR - 准备工作
  15. python集合使用范例的代码
  16. KXO151 Programming &amp; Problem Solving
  17. 浏览器虚拟过程IP插件
  18. 阿里云redis映射到阿里云服务器
  19. 【Excel】输出固定长文本
  20. rhel6+apache2.4+mysql5.7+php5.6部署LAMP架构

热门文章

  1. 使用NATS替换NSQ为后台服务解耦
  2. Blender 3D 打印插件Print Toolbox
  3. Mybatis(二,三)
  4. python------软件目录结构规范
  5. js实现一条抛物线
  6. mongodb启动很慢
  7. day1 python学习
  8. 05机器学习实战之Logistic 回归
  9. S老师 破坏神学习
  10. php 数组排序 按照某字段