当我们写类似下面代码时

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线程池执行方法了,如果有两个可能会占用两个被隔离的线程执行方法。

spring cloud 实践之hystrix注意事项的更多相关文章

  1. Spring Cloud入门教程-Hystrix断路器实现容错和降级

    简介 Spring cloud提供了Hystrix容错库用以在服务不可用时,对配置了断路器的方法实行降级策略,临时调用备用方法.这篇文章将创建一个产品微服务,注册到eureka服务注册中心,然后我们使 ...

  2. Spring Cloud 入门 之 Hystrix 篇(四)

    原文地址:Spring Cloud 入门 之 Hystrix 篇(四) 博客地址:http://www.extlight.com 一.前言 在微服务应用中,服务存在一定的依赖关系,如果某个目标服务调用 ...

  3. Spring Cloud实践:降级、限流、滚动、灰度、AB、金丝雀的实现思路

    端口:8888,方便起见直接读取配置文件,生产环境可以读取git.application-dev.properties为全局配置.先启动配置中心,所有服务的配置(包括注册中心的地址)均从配置中心读取. ...

  4. spring cloud中使用hystrix实现回退

    在微服务架构中,我们的服务被拆分成多个微服务,每个微服务完成自己的职责,微服务之间通过rpc或http进行调用.这个时候我们就要确保我们的服务高可用,但谁也说不准我们的服务能永远快速的提供服务.假如现 ...

  5. Spring Cloud Feign 整合 Hystrix

    在前面随笔Spring Cloud 之 Feign的feign工程基础上进行改造 1.pom.xml依赖不变 2.application.yml文件添加feign.hystrix.enabled=tr ...

  6. Spring Cloud Ribbon 整合 Hystrix

    在前面随笔 Spring Cloud 之 Ribbon 的ribbon工程基础上进行改造 1.pom.xml 加入依赖 <dependency> <groupId>org.sp ...

  7. 架构师入门:Spring Cloud系列,Hystrix与Eureka的整合

    和Ribbon等组件一样,在项目中,Hystrix一般不会单独出现,而是会和Eureka等组件配套出现.在Hystrix和Eureka整合后的框架里,一般会用到Hystrix的断路器以及合并请求等特性 ...

  8. spring cloud 实践坑点记录

    用spring cloud 微服务框架有一段时间了有一些坑点在这里给大家记录一下希望大家用得着 1.当我们使用聚合性能监控的时候,我们采用 rabbitmq作为消息中间件来收集性能信息最后在使用Tur ...

  9. Spring Cloud(Dalston.SR5)--Hystrix 断路器-缓存

    在 Spring Cloud 中可以使用注解的方式来支持 Hystrix 的缓存,缓存与合并请求功能需要先初始化请求上下文才能实现,因此,必须实现 javax.servlet.Filter 用于创建和 ...

随机推荐

  1. Linux--Introduction and Basic commands(Part one)

    Welcome to Linux world! Introduction and Basic commands--Part one J.C 2018.3.11 Chapter 1 What Is Li ...

  2. 原创SQlServer数据库生成简单的说明文档包含(存储过程、视图、数据库批量备份)小工具(附源码)

    这是一款简单的数据库文档生成工具,主要实现了SQlServer生成说明文档的小工具,目前不够完善,主要可以把数据库的表以及表的详细字段信息,导出到 Word中,可以方便开发人员了解数据库的信息或写技术 ...

  3. This relative module was not found (转载)

    vue踩坑-This relative module was not found 在使用vue.js的日期选择插件 的时候,报错如下   This relative module was not fo ...

  4. Ext.isEmpty()的使用

    说明如下: isEmpty( Object value, Boolean allowEmptyString ) : Boolean 如果传递的值为空,则返回 true,否则返回 false.该值被认为 ...

  5. JAVA 多线程(4)

    接着3说: 一.String常量池 先回顾 java 的基本数据类型: 变量就是申请内存来存储值.也就是说,当创建变量的时候,需要在内存中申请空间. 内存管理系统根据变量的类型为变量分配存储空间,分配 ...

  6. es6 语法 (Decorator)

    修饰器是一个函数,用来修改类的行为(注意:1.函数  2.修改行为  3.对类进行操作) { //修饰器函数定义 target:类本身,name名称,descriptor描述 let readonly ...

  7. [jQuery]相对父级元素的fixed定位

    (function($) {     var DNG = {};     //----------------------------------------------------/     // ...

  8. P2590 [ZJOI2008]树的统计

    题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u ...

  9. cf438E. The Child and Binary Tree(生成函数 多项式开根 多项式求逆)

    题意 链接 Sol 生成函数博大精深Orz 我们设\(f(i)\)表示权值为\(i\)的二叉树数量,转移的时候可以枚举一下根节点 \(f(n) = \sum_{w \in C_1 \dots C_n} ...

  10. [IB]Integration Broker 是如何处理传入的请求(Part 2)

    让我们讨论一下集成代理如何处理传入的请求.可以先阅读(理解PeopleSoft集成代理 Part1). 当PeopleSoft集成代理接收传入请求时,会发生一系列事件. 当侦听连接器(Listenin ...