Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ThreadLocalUtil {
- private static ThreadLocal<Integer> idTL = new ThreadLocal<>();
- public static void setId(Integer id) {
- idTL.set(id);
- }
- public static void getId() {
- idTL.get();
- }
- public static void clear() {
- idTL.remove();
- }
- }
- public class ConcurrencyStrategy extends HystrixConcurrencyStrategy {
- @Override
- public <T> Callable<T> wrapCallable(Callable<T> callable) {
- Integer id = ThreadLocalUtil.getId();
- try {
- return () -> {
- ThreadLocalUtil.setId(id);
- return callable.call();
- };
- } finally {
- // Remember to clear thee threadLocals
- ThreadLocalUtil.clear()
- }
- }
- }
- // Register the concurrency strategy
- HystrixPlugins.getInstance().registerConcurrencyStrategy(new ConcurrencyStrategy());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement