Created
March 30, 2017 14:22
-
-
Save vladimir-bukhtoyarov/2295e012c4d36db74ed0f5fddd0671b3 to your computer and use it in GitHub Desktop.
Example of running hystrix command in current thread instead of dedicated thread pool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.netflix.hystrix.HystrixCommand; | |
import com.netflix.hystrix.HystrixCommandGroupKey; | |
import com.netflix.hystrix.HystrixCommandProperties; | |
public class HystrixRunInCallerThread { | |
static HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter() | |
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE) | |
.withExecutionIsolationSemaphoreMaxConcurrentRequests(10) | |
; | |
public static void main(String[] args) { | |
System.out.println(Thread.currentThread().getName()); | |
HystrixCommand.Setter cmdSetter = HystrixCommand.Setter | |
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("test")) | |
.andCommandPropertiesDefaults(setter) | |
; | |
HystrixCommand<String> command = new HystrixCommand<String>(cmdSetter) { | |
@Override | |
protected String run() throws Exception { | |
System.out.println(Thread.currentThread().getName()); | |
return "42"; | |
} | |
}; | |
command.execute(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment