Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vladimir-bukhtoyarov/2295e012c4d36db74ed0f5fddd0671b3 to your computer and use it in GitHub Desktop.
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
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