| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
我用反射改成了使用阿里的TTL的线程池了 //初始化为微信的公共包数据
static {
//改变threadLocal为ttl的
setTTlThreadPool();
}
@SneakyThrows
@SuppressWarnings({"rawtypes", "unchecked"})
private static void setTTlThreadPool() {
TransmittableThreadLocal<String> ttlThreadLocal = new TransmittableThreadLocal() {
@Override
protected String initialValue() {
return "default";
}
};
Field threadLocal = ReflectionUtils.findField(WxMaConfigHolder.class, "THREAD_LOCAL");
if (threadLocal != null) {
ReflectionUtils.makeAccessible(threadLocal);
Field modifiers = ReflectionUtils.findField(threadLocal.getClass(), StringPool.MODIFIERS);
if (modifiers != null) {
ReflectionUtils.makeAccessible(modifiers);
ReflectionUtils.setField(modifiers, threadLocal, threadLocal.getModifiers() ^ Modifier.FINAL);
}
ReflectionUtils.setField(threadLocal, WxMaConfigHolder.class, ttlThreadLocal);
}
} |
Sorry, something went wrong.
|
原先没有这个功能的时候是从context上下文中传递过去的,比较麻烦: private void route(WxMaMessage message, String appid) {
//将appid传递到过去,否则如果是异步路由,无法从threadLocal中获取当前appid
Map<String, Object> context = new HashMap<>();
context.put(WxampContextConstants.APPID, appid);
try {
wxMaMessageRouter.route(message, context);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
|
Sorry, something went wrong.
是的,在实际业务执行的handler里面如果有对微信请求的话,里面还需要设置一遍,比较麻烦。 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
小程序异步执行消息路由时子线程添加appid