本文主要参考:
需要在实现的时候记得
在继承hystrixCommand的构造函数中实现添加线程池参数记性资源隔离。
public CommandHelloWorld(String name) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
.andCommandKey(HystrixCommandKey.Factory.asKey("HelloWorld"))
.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("HelloWorldPool")));
this.name = name;
}
Here is a simple example:
- two commands used to access Video metadata
- group name is “VideoMetadata”
- command A goes against resource #1
- command B goes against resource #2
If command A becomes latent and saturates its thread-pool it should not prevent command B from executing requests since they each hit different back-end resources.
Thus, we logically want these commands grouped together but want them isolated differently and would use HystrixThreadPoolKey to give each of them a different thread-pool.
从这里的说明能够看出,对于不同的资源应该试用不同的线程池进行隔离。不然会出现A资源和B资源共用一个资源池的情况下,如果A出现问题,导致线程池饱和,资源B没有线程可用。