【Spring Cloud 8】熔断与限流Sentinel,java面试常见问题及回答技巧

本文深入探讨Sentinel的核心概念,包括Entry、DefaultNode、StatisticNode和Slot,阐述其在资源管理和流量控制中的作用。同时,通过示例介绍了如何在Spring Cloud项目中集成和使用Sentinel,帮助理解Sentinel的工作流程和实际应用。
摘要由CSDN通过智能技术生成

一个Context生命周期内Context只能初始化一次,存到ThreadLocal中,并且只有在非NULL时才会进行初始化。如果想在调用SphU.entry()或SphO.entry()前,自定义一个context,则通过ContextUtil.enter()方法来创建。context保存在ThreadLocal中,每次执行的时候会优先到ThreadLocal中获取,为null时会创建一个context。当Entry执行exit方法时,如果entry的parent节点为null,表示当前context中最外层的entry了,此时将threadLocals中的context清空。

3、Entry

每次执行SphU.entry()或SphO.entry()都会返回一个Entry,Entry表示一次资源操作,内部会保存单签invocation信息。在一个context声明周期中多次资源操作,也就是对应多个Entry,parent/child结构保存在Entry实例中,Entry类CtEntry结构如下:

class CtEntry extends Entry {

protected Entry parent = null;

protected Entry child = null;

protected ProcessorSlot chain;

protected Context context;

}

public abstract class Entry implements AutoCloseable {

private long createTime;

private Node curNode;

/**

  • {@link Node} of the specific origin, Usually the origin is the Service Consumer.

*/

private Node originNode;

private Throwable error; // 是否出现异常

protected ResourceWrapper resourceWrapper; // 资源信息

}

4、DefaultNode

Node默认实现类DefaultNode,该类还有一个子类EntranceNode;context有一个entranceNode属性,Entry中有一个curNode属性。

    <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值