Last active
December 18, 2019 02:39
-
-
Save yp-palF/1f0803d57048a858093283864af0eeb5 to your computer and use it in GitHub Desktop.
This file contains 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
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); | |
T result = callable.call(); | |
ThreadLocalUtil.clear(); | |
return result; | |
}; | |
} | |
} | |
} | |
// Register the concurrency strategy | |
HystrixPlugins.getInstance().registerConcurrencyStrategy(new ConcurrencyStrategy()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment