TODO: 线程池线程异常,处理???
- Add Dependency
<!-- replace here with the latest version -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>1.8.0</version>
</dependency>
- Define Resource
//
> - 2. Define Resource
try (Entry entry = SphU.entry("HelloWorld")) {
// Your business logic here.
System.out.println("hello world");
} catch (BlockException e) {
// Handle rejected request.
e.printStackTrace();
}
// try-with-resources auto exit
- Define Resource
List<FlowRule> rules = new ArrayList<>();
FlowRule rule = new FlowRule();
rule.setResource("HelloWorld");
// set limit qps to 20
rule.setCount(20);
rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
rules.add(rule);
FlowRuleManager.loadRules(rules);
Histrix和Sentinel的资源线程隔离方式不一样,Sentinel无需线程上下文切换,Histrix需要,Sentilen直接统计资源正在使用的线程数量,Histrix是直接对每个资源使用不同的线程池;
Sentinel相对于Histrix的突出优点:
服务流控、集群流控、网关流控;
热点限流、自适应限流;
慢调用比例、异常比例、异常数,熔断,时间窗口;
来源:oschina
链接:https://my.oschina.net/mojiewhy/blog/4818899