当我们写类似下面代码时

package demo1.demo1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; @RestController
public class TestRest { protected final static Logger logger = LoggerFactory.getLogger(TestRest.class);
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "20000") }, threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "64") }, threadPoolKey = "test1")
@GetMapping("/testdemo1")
public long getStringtest2() {
logger.info("我收到了其他服务调用");
// 返回当前时间毫秒 来发现访问变化 return System.currentTimeMillis();
} }

如果方法之间有嵌套(注意不要像下面那样写

package demo1.demo1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; @RestController
public class TestRest { protected final static Logger logger = LoggerFactory.getLogger(TestRest.class);
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "20000") }, threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "64") }, threadPoolKey = "test1")
@GetMapping("/testdemo1")
public long getStringtest2() {
logger.info("我收到了其他服务调用");
// 返回当前时间毫秒 来发现访问变化 //报个异常试试
//int a=1/0;
test(); return System.currentTimeMillis();
}
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "20000") }, threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "64") }, threadPoolKey = "test1")
private void test(){
//code } }

因为使用了@HystrixCommand注解之后方法会放到隔离线程池中执行已经不再是tomcat或jetty等容器创建的web http线程池执行方法了,如果有两个可能会占用两个被隔离的线程执行方法。

最新文章

  1. iOS开发中的错误整理,通过storyboard做项目,遇到view看不见,或者view被压缩的情况
  2. sql工作问题总结
  3. NULL不能和任何字段比较和运算
  4. css07家用电器分类
  5. AlexNet 网络详解及Tensorflow实现源码
  6. jquery-bootgrid
  7. 金蝶K/3 审批相关SQL语句
  8. HTML5新增常用属性
  9. NLP相似度之tf-idf计算
  10. C语言列出真分数序列代码及解析
  11. JQuery operate xml
  12. Linux上启动Cron任务
  13. 如何获取阿里云OSS上每个文件夹的大小
  14. 构建最小JDK Docker镜像
  15. NIO的Buffer&Channel&Selector
  16. 求XF+闭包(第十一届河南省省赛真题)
  17. 【转】Fiddler工作原理
  18. MySQL存储过程、触发器 小例子
  19. 单网卡用双IP上内外网
  20. django-session和cookie

热门文章

  1. IE的浏览器模式、文本模式
  2. Web网站配置Gzip,压缩js css文件
  3. TypeScript学习(2)
  4. .Net NPOI 根据excel模板导出excel、直接生成excel
  5. [angularjs] angularjs系列笔记(四)过滤器
  6. DoTween 动画插件简单示例
  7. node实现简单的群体聊天工具
  8. [小知识点] react 性能
  9. 使用CSS实现无滚动条滚动
  10. favicon.ico在chrome里显示正常,在ie,edge浏览器中不显示