mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-24 08:57:16 +08:00
#535 修复Tomcat 不能正常关闭的问题,增加线程池shutdown相关的操作
This commit is contained in:
parent
a0240e7847
commit
558f4e7880
@ -75,6 +75,29 @@ public class WxMpMessageRouter {
|
||||
this.exceptionHandler = new LogExceptionHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 使用自定义的 {@link ExecutorService}
|
||||
* </pre>
|
||||
*/
|
||||
public WxMpMessageRouter(WxMpService wxMpService, ExecutorService executorService) {
|
||||
this.wxMpService = wxMpService;
|
||||
this.executorService = executorService;
|
||||
this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
|
||||
this.sessionManager = new StandardSessionManager();
|
||||
this.exceptionHandler = new LogExceptionHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 如果使用默认的 {@link ExecutorService},则系统退出前,应该调用该方法。
|
||||
* </pre>
|
||||
*/
|
||||
public void shutDownExecutorService() {
|
||||
this.executorService.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 设置自定义的 {@link ExecutorService}
|
||||
|
@ -8,6 +8,8 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -67,9 +69,23 @@ public class WxMpMessageRouterTest {
|
||||
prepare(true, sb, router);
|
||||
router.route(message);
|
||||
Thread.sleep(500);
|
||||
router.shutDownExecutorService();
|
||||
Assert.assertEquals(sb.toString(), expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "messages-1")
|
||||
public void testExternalExcutorService(WxMpXmlMessage message, String expected) throws InterruptedException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(100);
|
||||
WxMpMessageRouter router = new WxMpMessageRouter(null, executorService);
|
||||
prepare(true, sb, router);
|
||||
router.route(message);
|
||||
Thread.sleep(500);
|
||||
executorService.shutdown();
|
||||
Assert.assertEquals(sb.toString(), expected);
|
||||
}
|
||||
|
||||
|
||||
public void testConcurrency() throws InterruptedException {
|
||||
final WxMpMessageRouter router = new WxMpMessageRouter(null);
|
||||
router.rule().handler(new WxMpMessageHandler() {
|
||||
|
Loading…
Reference in New Issue
Block a user