{"action":"created","issue":{"url":"https://api.github.com/repos/wechat-group/weixin-java-tools/issues/23","repository_url":"https://api.github.com/repos/wechat-group/weixin-java-tools","labels_url":"https://api.github.com/repos/wechat-group/weixin-java-tools/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/wechat-group/weixin-java-tools/issues/23/comments","events_url":"https://api.github.com/repos/wechat-group/weixin-java-tools/issues/23/events","html_url":"https://github.com/wechat-group/weixin-java-tools/issues/23","id":171346875,"number":23,"title":"WxMpServiceImpl.executeInternal 方法阻塞导致服务器宕机的问题","user":{"login":"WesleyWu","id":833816,"avatar_url":"https://avatars.githubusercontent.com/u/833816?v=3","gravatar_id":"","url":"https://api.github.com/users/WesleyWu","html_url":"https://github.com/WesleyWu","followers_url":"https://api.github.com/users/WesleyWu/followers","following_url":"https://api.github.com/users/WesleyWu/following{/other_user}","gists_url":"https://api.github.com/users/WesleyWu/gists{/gist_id}","starred_url":"https://api.github.com/users/WesleyWu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WesleyWu/subscriptions","organizations_url":"https://api.github.com/users/WesleyWu/orgs","repos_url":"https://api.github.com/users/WesleyWu/repos","events_url":"https://api.github.com/users/WesleyWu/events{/privacy}","received_events_url":"https://api.github.com/users/WesleyWu/received_events","type":"User","site_admin":false},"labels":[{"id":307575424,"url":"https://api.github.com/repos/wechat-group/weixin-java-tools/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-08-16T07:55:15Z","updated_at":"2016-11-16T05:26:14Z","closed_at":null,"body":"目前方法的签名是这样的：\n\nprotected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {...}\n\n里边执行了一个超耗时的https的阻塞请求，直到微信官方网站返回了执行结果，才会结束这个方法。\n\n所以，如果有多个线程通知执行 execute （然后 executeInternal），比如通过16个线程同时发送100万个模板消息，早晚都一定会发生一大堆线程阻塞在这个方法的起始处。\n\n我们就遇到了这个情况，用 jstack 查看我们的 jvm 的线程状况，大部分都这样：\n\"http-nio-8081-exec-188\" #1201 daemon prio=5 os_prio=0 tid=0x00007f99f0498000 nid=0x4822 waiting for monitor entry [0x00007f99c6ef4000]\n   java.lang.Thread.State: BLOCKED (on object monitor)\n        at me.chanjar.weixin.mp.api.WxMpServiceImpl.executeInternal(WxMpServiceImpl.java:729)\n        - waiting to lock <0x00000000c7332ed8> (a me.chanjar.weixin.mp.api.impl.WxMpServiceImpl)\n        at me.chanjar.weixin.mp.api.WxMpServiceImpl.execute(WxMpServiceImpl.java:705)\n\n于是，整个jvm的线程数量耗尽，导致tomcat假死，服务器资源消耗基本为0。\n\n所以我的问题如下：\n1、这里的这个 synchronized 关键字为什么一定要加？\n2、可以去掉不？\n3、如果去掉，会导致什么严重问题？\n\n感谢。\n"},"comment":{"url":"https://api.github.com/repos/wechat-group/weixin-java-tools/issues/comments/260857505","html_url":"https://github.com/wechat-group/weixin-java-tools/issues/23#issuecomment-260857505","issue_url":"https://api.github.com/repos/wechat-group/weixin-java-tools/issues/23","id":260857505,"user":{"login":"yigubigu","id":3191827,"avatar_url":"https://avatars.githubusercontent.com/u/3191827?v=3","gravatar_id":"","url":"https://api.github.com/users/yigubigu","html_url":"https://github.com/yigubigu","followers_url":"https://api.github.com/users/yigubigu/followers","following_url":"https://api.github.com/users/yigubigu/following{/other_user}","gists_url":"https://api.github.com/users/yigubigu/gists{/gist_id}","starred_url":"https://api.github.com/users/yigubigu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yigubigu/subscriptions","organizations_url":"https://api.github.com/users/yigubigu/orgs","repos_url":"https://api.github.com/users/yigubigu/repos","events_url":"https://api.github.com/users/yigubigu/events{/privacy}","received_events_url":"https://api.github.com/users/yigubigu/received_events","type":"User","site_admin":false},"created_at":"2016-11-16T05:26:14Z","updated_at":"2016-11-16T05:26:14Z","body":"#1 使用redis，把access_token\r\n#2 中控服务器定期刷新，拿到后立即更新\r\n#3保 证刷新的线程是高优先级，能够始终执行"}}
{"actor":{"display_login":"yigubigu"}}