GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — 增加企业微信路由线程池关闭方法 by nadirvishun · Pull Request #2583 · binarywang/WxJava Conversation
|
|
请问shutDownExecutorService这个方法是手动调用,还是每次http关闭时会自动调用该方法? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
请问下,这个shutDownExecutorService这个方法应该在哪里去调用? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
我这边是整个spring项目关闭时才需要手动调用执行,而不是单个http请求就要关闭,而且是只有优雅关闭时才需要,如果强制结束进程调不调用都无所谓。处理的方式是用
/** * 结束时关闭路由线程池 */ @PreDestroy public void destroy() { messageRouter.shutDownExecutorService(5); }
/** * 结束时关闭线程池 */ @PreDestroy public void destroy() { List<WxCpMessageRouter> messageRouterList = new ArrayList<>(routers.values()); if (messageRouterList.size() > 0) { for (WxCpMessageRouter messageRouter : messageRouterList) { messageRouter.shutDownExecutorService(5); } } } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
如果是整个spring项目关闭时才需要手动调用执行,并不能解决因为jvm的设置导致创建线程过多自动宕机的。以下是我的错误日志。 Stack: [0x00007f87ccec4000,0x00007f87ccf45000], sp=0x00007f87ccf437a0, free space=509k --------------- P R O C E S S --------------- Java Threads: ( => current thread ) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
目前我将shutDownExecutorService方法加在 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
这样不行吧?如果放到这里关闭了,下次再来一个消息怎么办?你在哪里重新创建线程池的?
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
每次收到一个事件推送就会创建一次呀 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
demo中都是先建好存起来,用的时候直接调用,如果你那边能保证能新建,逻辑上倒是没什么问题,但是线程池的目的就是为了线程复用,避免线程创建销毁带来的性能消耗的。如果这样频繁创新关闭。。。。 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
你可以debug看下,每次请求有没有新建的,我目前没有用到异步路由,也是有创建的 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
是说路由的新建吗?这个官方只是给了个demo,实际上每个人的实现可都不一样,如果是按照weixin-java-cp-demo来的话(这是企业微信自建应用的,没找到企业微信第三方的demo),每次来消息并不需要要新建啊。 private WxCpMessageRouter newRouter(WxCpService wxCpService) { final val newRouter = new WxCpMessageRouter(wxCpService); // 记录所有事件的日志 (异步执行) newRouter.rule().handler(this.logHandler).next(); ... } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
自建和第三方实现都是一样的,你可以把断点打在源码上,然后模拟请求发送,看源码的执行。 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
我实在是没看出来哪里需要新建啊,不是在WxCpConfiguration中初始化时就按照应用来把路由创建好了,然后存到map中了吗?还有如果没有异步路由压根不会走线程池啊,不如你好好对比下和demo是否一致,或者是贴一下你写的配置类WxCpConfiguration 和入口类WxPortalController的代码看下啊。 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
断点打在WxCpTpMessageRouter源码的构造方法上 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
对于第一个,如果你是按照demo来,这个只有在 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Tomcat 不能 graceful shutdown
There was an error while loading. Please reload this page.