spring cloud 实践之hystrix注意事项
当我们写类似下面代码时
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注意事项的更多相关文章
- Spring Cloud入门教程-Hystrix断路器实现容错和降级
简介 Spring cloud提供了Hystrix容错库用以在服务不可用时,对配置了断路器的方法实行降级策略,临时调用备用方法.这篇文章将创建一个产品微服务,注册到eureka服务注册中心,然后我们使 ...
- Spring Cloud 入门 之 Hystrix 篇(四)
原文地址:Spring Cloud 入门 之 Hystrix 篇(四) 博客地址:http://www.extlight.com 一.前言 在微服务应用中,服务存在一定的依赖关系,如果某个目标服务调用 ...
- Spring Cloud实践:降级、限流、滚动、灰度、AB、金丝雀的实现思路
端口:8888,方便起见直接读取配置文件,生产环境可以读取git.application-dev.properties为全局配置.先启动配置中心,所有服务的配置(包括注册中心的地址)均从配置中心读取. ...
- spring cloud中使用hystrix实现回退
在微服务架构中,我们的服务被拆分成多个微服务,每个微服务完成自己的职责,微服务之间通过rpc或http进行调用.这个时候我们就要确保我们的服务高可用,但谁也说不准我们的服务能永远快速的提供服务.假如现 ...
- Spring Cloud Feign 整合 Hystrix
在前面随笔Spring Cloud 之 Feign的feign工程基础上进行改造 1.pom.xml依赖不变 2.application.yml文件添加feign.hystrix.enabled=tr ...
- Spring Cloud Ribbon 整合 Hystrix
在前面随笔 Spring Cloud 之 Ribbon 的ribbon工程基础上进行改造 1.pom.xml 加入依赖 <dependency> <groupId>org.sp ...
- 架构师入门:Spring Cloud系列,Hystrix与Eureka的整合
和Ribbon等组件一样,在项目中,Hystrix一般不会单独出现,而是会和Eureka等组件配套出现.在Hystrix和Eureka整合后的框架里,一般会用到Hystrix的断路器以及合并请求等特性 ...
- spring cloud 实践坑点记录
用spring cloud 微服务框架有一段时间了有一些坑点在这里给大家记录一下希望大家用得着 1.当我们使用聚合性能监控的时候,我们采用 rabbitmq作为消息中间件来收集性能信息最后在使用Tur ...
- Spring Cloud(Dalston.SR5)--Hystrix 断路器-缓存
在 Spring Cloud 中可以使用注解的方式来支持 Hystrix 的缓存,缓存与合并请求功能需要先初始化请求上下文才能实现,因此,必须实现 javax.servlet.Filter 用于创建和 ...
随机推荐
- SpringBoot学习(六)-->SpringBoot的自动配置的原理
Spring Boot的自动配置的原理 Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入 ...
- React Fiber源码分析 第一篇
先附上流程图一张 先由babel编译, 调用reactDOM.render,入参为element, container, callback, 打印出来可以看到element,container,cal ...
- 第一册:lesson eighty three.
原文:Going on holiday. A:Hello Sam, come in. B:Hi,Sam.We are having lunch. Do you want to have lunch w ...
- Linux学习笔记之如何挂载数据盘
一.引入 双11在阿里云买了一台服务器(Linux操作系统,版本:CentOS7.04),配置就是20G的系统盘和40G的数据盘,可是问题来了,当系统初始化登录进去之后,输入:free -h命令并不能 ...
- mybatis_03_ mapper代理方式实现MyBatis的Dao编写
不是用mapper代理方式也能够实现,但是不推荐 Mapper代理的开发方式,程序员只需要编写mapper接口(相当于dao接口)即可.Mybatis会自动的为mapper接口生成动态代理实现类. 不 ...
- 解决org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered from2 to 0
错误信息 严重: Servlet.service() for servlet [springmvc] in context with path [/order] threw exception [Re ...
- JSJ—类与对象
当你在设计类时,要记得对象时靠类的模型塑造出来的,你可以这样看: ——对象是已知事物 ——对象会执行的动作 对象本身已知的事物称为实例变量,它们代表对象的状态(数据),且该类型的每一个对象都会独立的拥 ...
- 博弈之——SG模板
很久没搞博弈了.先来写个模板: 现在我们来研究一个看上去似乎更为一般的游戏:给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移动者判负.事实上,这个游戏可以 ...
- Java基础IO流(三)字符流
字符流: 文本和文本文件: java的文本(char)是16位无符号整数,是字符的unicode编码(双字节编码)文件是byte byte byte....的数据序列,而文本文件是文本(char)序列 ...
- Hibernate入门(八)级联保存或更新(含问题在末尾,求大佬指点..)
级联保存或更新CASCADE 级联保存或更新: 作用就是:保存一方的数据的时候,会把关联的对象也同时保存. 级联保存或更新的配置: 属性名:cascade 属性值: 1.none:所有情况下均不进行关 ...