File tree Expand file tree Collapse file tree
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4141 */
4242public class WxCpMessageRouter {
4343
44+ private static final int DEFAULT_THREAD_POOL_SIZE = 20 ;
45+
4446 private final List <Rule > rules = new ArrayList <Rule >();
4547
46- private final ExecutorService es = Executors . newCachedThreadPool () ;
48+ private final ExecutorService executorService ;
4749
4850 private final WxCpService wxCpService ;
4951
5052 public WxCpMessageRouter (WxCpService wxCpService ) {
5153 this .wxCpService = wxCpService ;
54+ this .executorService = Executors .newFixedThreadPool (DEFAULT_THREAD_POOL_SIZE );
55+ }
56+
57+ public WxCpMessageRouter (WxCpService wxMpService , int threadPoolSize ) {
58+ this .wxCpService = wxMpService ;
59+ this .executorService = Executors .newFixedThreadPool (threadPoolSize );
5260 }
5361
5462 /**
@@ -79,7 +87,7 @@ public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
7987 if (matchRules .get (0 ).async ) {
8088 // 只要第一个是异步的,那就异步执行
8189 // 在另一个线程里执行
82- es .submit (new Runnable () {
90+ executorService .submit (new Runnable () {
8391 public void run () {
8492 for (final Rule rule : matchRules ) {
8593 rule .service (wxMessage );
Original file line number Diff line number Diff line change 4040 *
4141 */
4242public class WxMpMessageRouter {
43-
43+
44+ private static final int DEFAULT_THREAD_POOL_SIZE = 20 ;
45+
4446 private final List <Rule > rules = new ArrayList <Rule >();
4547
46- private final ExecutorService executorService = Executors . newCachedThreadPool () ;
48+ private final ExecutorService executorService ;
4749
4850 private final WxMpService wxMpService ;
4951
5052 public WxMpMessageRouter (WxMpService wxMpService ) {
5153 this .wxMpService = wxMpService ;
54+ this .executorService = Executors .newFixedThreadPool (DEFAULT_THREAD_POOL_SIZE );
55+ }
56+
57+ public WxMpMessageRouter (WxMpService wxMpService , int threadPoolSize ) {
58+ this .wxMpService = wxMpService ;
59+ this .executorService = Executors .newFixedThreadPool (threadPoolSize );
5260 }
5361
5462 /**
@@ -79,7 +87,7 @@ public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
7987 if (matchRules .get (0 ).async ) {
8088 // 只要第一个是异步的,那就异步执行
8189 // 在另一个线程里执行
82- executorService .submit (new Runnable () {
90+ executorService .execute (new Runnable () {
8391 public void run () {
8492 for (final Rule rule : matchRules ) {
8593 rule .service (wxMessage );
You can’t perform that action at this time.
0 commit comments