Sentinel
Sentinel copied to clipboard
ContextUtil为什么要实例化一个“sentinel_default_context”
读源代码(版本:1.8.2
)时, com.alibaba.csp.sentinel.context.ContextUtil
提供有 initDefaultContext()
方法,并在 static
块中初始化了一个sentinel_default_context
,位置如图:
在测试过程中,有三个不同的场景,如图:
说明:
场景 ① 是
main
方法直接跑的,生成了默认的 sentinel_default_context
场景 ② 是 web
应用,使用了 com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor
, 生成了默认的 sentinel_default_context
和 sentinel_spring_web_context
场景 ③ 是 thrift
应用,使用了自定义的 CustomSentinelResourceAspect
(继承自 com.alibaba.csp.sentinel.annotation.aspectj.AbstractSentinelAspectSupport
,并使用了自定义的feature_thrift_context
),生成了默认的 sentinel_default_context
及自定义的 feature_thrift_context
问题:
1、我理解,默认的 sentinel_default_context
是用来兜底的,是否还有其它作用?
2、如果用户指定了自己的 context
,这个默认的 sentinel_default_context
是不是不应该创建?
3、如果第 2、
个问题是合理的,代码是不是有bug,不应该直接在 static
块中始化默认的sentinel_default_context
,而在流程走到com.alibaba.csp.sentinel.context.ContextUtil#enter(java.lang.String name, java.lang.String origin)
中再确定是否需要创建?