This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 1523c30ca [ISSUE #3171] change threadPool to CachedThreadPool from
ForkJoinPool (#3172)
1523c30ca is described below
commit 1523c30ca64bff678e9630fd5b06c051efa2aee9
Author: dragon-zhang <[email protected]>
AuthorDate: Fri Apr 15 10:30:47 2022 +0800
[ISSUE #3171] change threadPool to CachedThreadPool from ForkJoinPool
(#3172)
* [ISSUE #3171] change threadPool to CachedThreadPool from ForkJoinPool
* support config core threads, max threads and max queues
* sql move to 2.5.0 version
---
script/2.4.2-upgrade-2.4.3-mysql.sql | 2 +-
script/2.4.2-upgrade-2.4.3-pg.sql | 2 +-
script/2.4.3-upgrade-2.5.0-mysql.sql | 27 ++++++++
script/2.4.3-upgrade-2.5.0-pg.sql | 27 ++++++++
.../src/main/resources/sql-script/h2/schema.sql | 5 +-
.../src/main/resources/sql-script/mysql/schema.sql | 5 +-
.../src/main/resources/sql-script/pg/schema.sql | 5 +-
.../dto/convert/plugin/MotanRegisterConfig.java | 76 +++++++++++++++++++++-
.../plugin/motan/proxy/MotanProxyService.java | 32 ++++++++-
9 files changed, 171 insertions(+), 10 deletions(-)
diff --git a/script/2.4.2-upgrade-2.4.3-mysql.sql
b/script/2.4.2-upgrade-2.4.3-mysql.sql
index 96249d013..ba43cf26b 100644
--- a/script/2.4.2-upgrade-2.4.3-mysql.sql
+++ b/script/2.4.2-upgrade-2.4.3-mysql.sql
@@ -53,7 +53,7 @@ INSERT IGNORE INTO shenyu_dict (`id`, `type`, `dict_code`,
`dict_name`, `dict_va
INSERT IGNORE INTO shenyu_dict (`id`, `type`, `dict_code`, `dict_name`,
`dict_value`, `desc`, `sort`, `enabled`) VALUES ('1509837592611110930',
'retryStrategy', 'RETRY_STRATEGY', 'failover', 'failover', 'failover', '1',
'1');
-- Note: it doesn't matter if you don't execute this SQL, the default
configuration will be compatible with the old version
--- Note: because most users have changed ZK configuration, this SQL is
annotated to prevent erroneous execution
+-- Note: because users may have changed configuration, this SQL is annotated
to prevent erroneous execution
-- UPDATE plugin SET
config='{"multiSelectorHandle":"1","multiRuleHandle":"0","threadpool":"cached"}'
WHERE `name` = 'grpc';
-- if you want to execute this SQL, please replace these with your own
configuration
diff --git a/script/2.4.2-upgrade-2.4.3-pg.sql
b/script/2.4.2-upgrade-2.4.3-pg.sql
index 1eaf8fce1..b22b076d2 100644
--- a/script/2.4.2-upgrade-2.4.3-pg.sql
+++ b/script/2.4.2-upgrade-2.4.3-pg.sql
@@ -71,7 +71,7 @@ INSERT IGNORE INTO plugin_handle (`id`,
`plugin_id`,`field`,`label`,`data_type`,
INSERT IGNORE INTO plugin_handle (`id`,
`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES
('1509837592623693848', '29', 'topic', 'topic', 2, 1, 1,
'{"required":"0","defaultValue":"","placeholder":"optional"}');
INSERT IGNORE INTO plugin_handle (`id`,
`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES
('1509837592623693849', '29', 'sampleRate', 'sampleRate', 2, 1, 2,
'{"required":"0","defaultValue":"","placeholder":"optional,0,0.01~1"}');
-- Note: it doesn't matter if you don't execute this SQL, the default
configuration will be compatible with the old version
--- Note: because most users have changed ZK configuration, this SQL is
annotated to prevent erroneous execution
+-- Note: because users may have changed configuration, this SQL is annotated
to prevent erroneous execution
-- UPDATE plugin SET
config='{"multiSelectorHandle":"1","multiRuleHandle":"0","threadpool":"cached"}'
WHERE `name` = 'grpc';
-- if you want to execute this SQL, please replace these with your own
configuration
diff --git a/script/2.4.3-upgrade-2.5.0-mysql.sql
b/script/2.4.3-upgrade-2.5.0-mysql.sql
new file mode 100644
index 000000000..4323aaccc
--- /dev/null
+++ b/script/2.4.3-upgrade-2.5.0-mysql.sql
@@ -0,0 +1,27 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+-- this file works for MySQL.
+
+-- Note: it doesn't matter if you don't execute this SQL
+-- Note: because most users have changed ZK configuration, this SQL is
annotated to prevent erroneous execution
+-- UPDATE plugin SET
config='{"register":"127.0.0.1:2181","corethreads":0,"threads":2147483647,"queues":0}'
WHERE `name` = 'motan';
+-- if you want to execute this SQL, please replace it with your ZK
configuration
+
+-- insert plugin_handle data for motan
+INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`, `field`, `label`,
`data_type`, `type`, `sort`, `ext_obj`) VALUES ('1510270286164094976', '17',
'corethreads', 'corethreads', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"corethreads","rule":""}');
+INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`, `field`, `label`,
`data_type`, `type`, `sort`, `ext_obj`) VALUES ('1510270476329644032', '17',
'threads', 'threads', 1, 3, 0,
'{"required":"0","defaultValue":"2147483647","placeholder":"threads","rule":""}');
+INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`, `field`, `label`,
`data_type`, `type`, `sort`, `ext_obj`) VALUES ('1510270555383885824', '17',
'queues', 'queues', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"queues","rule":""}');
\ No newline at end of file
diff --git a/script/2.4.3-upgrade-2.5.0-pg.sql
b/script/2.4.3-upgrade-2.5.0-pg.sql
new file mode 100644
index 000000000..ab03e6f87
--- /dev/null
+++ b/script/2.4.3-upgrade-2.5.0-pg.sql
@@ -0,0 +1,27 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+-- this file works for PostgreSQL, can not use "`" syntax.
+
+-- Note: it doesn't matter if you don't execute this SQL
+-- Note: because most users have changed ZK configuration, this SQL is
annotated to prevent erroneous execution
+-- UPDATE plugin SET
config='{"register":"127.0.0.1:2181","corethreads":0,"threads":2147483647,"queues":0}'
WHERE `name` = 'motan';
+-- if you want to execute this SQL, please replace it with your ZK
configuration
+
+-- insert plugin_handle data for motan
+INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`, `field`, `label`,
`data_type`, `type`, `sort`, `ext_obj`) VALUES ('1510270286164094976', '17',
'corethreads', 'corethreads', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"corethreads","rule":""}');
+INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`, `field`, `label`,
`data_type`, `type`, `sort`, `ext_obj`) VALUES ('1510270476329644032', '17',
'threads', 'threads', 1, 3, 0,
'{"required":"0","defaultValue":"2147483647","placeholder":"threads","rule":""}');
+INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`, `field`, `label`,
`data_type`, `type`, `sort`, `ext_obj`) VALUES ('1510270555383885824', '17',
'queues', 'queues', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"queues","rule":""}');
\ No newline at end of file
diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
index 39f07f623..7ced265c4 100644
--- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
+++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
@@ -349,7 +349,7 @@ INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`,
`config`, `enabled`)
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('14', 'contextPath', 'HttpProcess', 80,'1');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('15', 'grpc', 'Proxy',
310,'{"multiSelectorHandle":"1","multiRuleHandle":"0","threadpool":"cached"}','0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('16', 'redirect', 'HttpProcess', 110,'0');
-INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('17', 'motan', 'Proxy',
310,'{"register":"127.0.0.1:2181"}','0');
+INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('17', 'motan', 'Proxy',
310,'{"register":"127.0.0.1:2181","corethreads":0,"threads":2147483647,"queues":0}','0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('18', 'logging', 'Logging', 160, '0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('19', 'jwt', 'Authentication', 30, '{"secretKey":"key"}',
'0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('20', 'request', 'HttpProcess', 120, '0');
@@ -523,6 +523,9 @@ INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`
/*insert plugin_handle data for plugin motan*/
INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'register', 'register', 2, 3, 0, null);
+INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'corethreads', 'corethreads', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"corethreads","rule":""}');
+INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'threads', 'threads', 1, 3, 0,
'{"required":"0","defaultValue":"2147483647","placeholder":"threads","rule":""}');
+INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'queues', 'queues', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"queues","rule":""}');
/*insert plugin_handle data for plugin mqtt*/
INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('28',
'port', 'port', 1, 3, 1, NULL);
diff --git a/shenyu-admin/src/main/resources/sql-script/mysql/schema.sql
b/shenyu-admin/src/main/resources/sql-script/mysql/schema.sql
index 58e449eab..1b130fa9a 100644
--- a/shenyu-admin/src/main/resources/sql-script/mysql/schema.sql
+++ b/shenyu-admin/src/main/resources/sql-script/mysql/schema.sql
@@ -354,7 +354,7 @@ INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`,
`config`, `enabled`)
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('14', 'contextPath', 'HttpProcess', 80,'1');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('15', 'grpc', 'Proxy',
310,'{"multiSelectorHandle":"1","multiRuleHandle":"0","threadpool":"cached"}','0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('16', 'redirect', 'HttpProcess', 110,'0');
-INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('17', 'motan', 'Proxy',
310,'{"register":"127.0.0.1:2181"}','0');
+INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('17', 'motan', 'Proxy',
310,'{"register":"127.0.0.1:2181","corethreads":0,"threads":2147483647,"queues":0}','0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('18', 'logging', 'Logging', 160, '0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('19', 'jwt', 'Authentication', 30, '{"secretKey":"key"}',
'0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('20', 'request', 'HttpProcess', 120, '0');
@@ -528,6 +528,9 @@ INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`
/*insert plugin_handle data for plugin motan*/
INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'register', 'register', 2, 3, 0, null);
+INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'corethreads', 'corethreads', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"corethreads","rule":""}');
+INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'threads', 'threads', 1, 3, 0,
'{"required":"0","defaultValue":"2147483647","placeholder":"threads","rule":""}');
+INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('17',
'queues', 'queues', 1, 3, 0,
'{"required":"0","defaultValue":"0","placeholder":"queues","rule":""}');
/*insert plugin_handle data for plugin mqtt*/
INSERT IGNORE INTO plugin_handle
(`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('28',
'port', 'port', 1, 3, 1, NULL);
diff --git a/shenyu-admin/src/main/resources/sql-script/pg/schema.sql
b/shenyu-admin/src/main/resources/sql-script/pg/schema.sql
index d48c81430..06a7354b8 100644
--- a/shenyu-admin/src/main/resources/sql-script/pg/schema.sql
+++ b/shenyu-admin/src/main/resources/sql-script/pg/schema.sql
@@ -366,7 +366,7 @@ ELSE
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '14' || ''', ''' || 'contextPath' || ''', NULL, ''' || 'HttpProcess' ||
''', 80, 1);');
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '15' || ''', ''' || 'grpc' || ''', ''' ||
'{"multiSelectorHandle":"1","multiRuleHandle":"0","threadpool":"cached"}' ||
''', ''' || 'Proxy' || ''', 310, 0);');
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '16' || ''', ''' || 'redirect' || ''', NULL, ''' || 'HttpProcess' ||
''', 110, 0);');
- PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '17' || ''', ''' || 'motan' || ''', ''' ||
'{"register":"127.0.0.1:2181"}' || ''', ''' || 'Proxy' || ''', 310, 0);');
+ PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '17' || ''', ''' || 'motan' || ''', ''' ||
'{"register":"127.0.0.1:2181","corethreads":0,"threads":2147483647,"queues":0}'
|| ''', ''' || 'Proxy' || ''', 310, 0);');
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '18' || ''', ''' || 'logging' || ''', NULL, ''' || 'Logging' || ''',
160, 0);');
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '19' || ''', ''' || 'jwt' || ''', ''' || '{"secretKey":"key"}' || ''',
''' || 'Authentication' || ''', 30, 0);');
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin" VALUES
(''' || '2' || ''', ''' || 'waf' || ''', ''' || '{"model":"black"}' || ''', '''
|| 'Authentication' || ''', 50, 0);');
@@ -609,6 +609,9 @@ ELSE
/*insert "plugin_handle" data for plugin motan*/
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin_handle" (
plugin_id , field , label , data_type , type , sort , ext_obj ) VALUES (''' ||
'17' || ''', ''' || 'register' || ''', ''' || 'register' || ''', 2, 3, 0,
null);');
+ PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin_handle" (
plugin_id , field , label , data_type , type , sort , ext_obj ) VALUES (''' ||
'17' || ''', ''' || 'corethreads' || ''', ''' || 'corethreads' || ''', 1, 3, 0,
''' ||
'{"required":"0","defaultValue":"0","placeholder":"corethreads","rule":""}' ||
''');');
+ PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin_handle" (
plugin_id , field , label , data_type , type , sort , ext_obj ) VALUES (''' ||
'17' || ''', ''' || 'threads' || ''', ''' || 'threads' || ''', 1, 3, 0, ''' ||
'{"required":"0","defaultValue":"2147483647","placeholder":"threads","rule":""}'
|| ''');');
+ PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin_handle" (
plugin_id , field , label , data_type , type , sort , ext_obj ) VALUES (''' ||
'17' || ''', ''' || 'queues' || ''', ''' || 'queues' || ''', 1, 3, 0, ''' ||
'{"required":"0","defaultValue":"0","placeholder":"queues","rule":""}' ||
''');');
/*insert plugin_handle data for plugin mqtt*/
PERFORM public.dblink_exec('init_conn', 'INSERT INTO "plugin_handle" (
plugin_id , field , label , data_type , type , sort , ext_obj ) VALUES (''' ||
'28' || ''', ''' || 'port' || ''', ''' || 'port' || ''', 1, 3, 1, null);');
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/MotanRegisterConfig.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/MotanRegisterConfig.java
index 12638fcf1..b4d44e0bc 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/MotanRegisterConfig.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/MotanRegisterConfig.java
@@ -25,8 +25,16 @@ import java.util.Objects;
*/
public class MotanRegisterConfig implements Serializable {
+ private static final long serialVersionUID = 2488053756247710408L;
+
private String register;
+ private Integer corethreads;
+
+ private Integer threads;
+
+ private Integer queues;
+
/**
* get register.
*
@@ -45,6 +53,60 @@ public class MotanRegisterConfig implements Serializable {
this.register = register;
}
+ /**
+ * get corethreads.
+ *
+ * @return corethreads
+ */
+ public Integer getCorethreads() {
+ return corethreads;
+ }
+
+ /**
+ * set corethreads.
+ *
+ * @param corethreads corethreads
+ */
+ public void setCorethreads(final Integer corethreads) {
+ this.corethreads = corethreads;
+ }
+
+ /**
+ * get threads.
+ *
+ * @return threads
+ */
+ public Integer getThreads() {
+ return threads;
+ }
+
+ /**
+ * set threads.
+ *
+ * @param threads threads
+ */
+ public void setThreads(final Integer threads) {
+ this.threads = threads;
+ }
+
+ /**
+ * get queues.
+ *
+ * @return queues
+ */
+ public Integer getQueues() {
+ return queues;
+ }
+
+ /**
+ * set queues.
+ *
+ * @param queues queues
+ */
+ public void setQueues(final Integer queues) {
+ this.queues = queues;
+ }
+
@Override
public boolean equals(final Object o) {
if (this == o) {
@@ -54,12 +116,13 @@ public class MotanRegisterConfig implements Serializable {
return false;
}
MotanRegisterConfig that = (MotanRegisterConfig) o;
- return Objects.equals(register, that.register);
+ return Objects.equals(register, that.register) &&
Objects.equals(corethreads, that.corethreads)
+ && Objects.equals(threads, that.threads) &&
Objects.equals(queues, that.queues);
}
@Override
public int hashCode() {
- return Objects.hash(register);
+ return Objects.hash(register, corethreads, threads, queues);
}
@Override
@@ -68,6 +131,15 @@ public class MotanRegisterConfig implements Serializable {
+ "register='"
+ register
+ '\''
+ + ", corethreads='"
+ + corethreads
+ + '\''
+ + ", threads='"
+ + threads
+ + '\''
+ + ", queues='"
+ + queues
+ + '\''
+ '}';
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
b/shenyu-plugin/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
index ec49b8a9c..1f2e99c58 100644
---
a/shenyu-plugin/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
+++
b/shenyu-plugin/shenyu-plugin-motan/src/main/java/org/apache/shenyu/plugin/motan/proxy/MotanProxyService.java
@@ -22,12 +22,15 @@ import com.weibo.api.motan.proxy.CommonHandler;
import com.weibo.api.motan.rpc.ResponseFuture;
import com.weibo.api.motan.rpc.RpcContext;
import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.common.concurrent.ShenyuThreadFactory;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.MetaData;
+import org.apache.shenyu.common.dto.convert.plugin.MotanRegisterConfig;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.enums.ResultEnum;
import org.apache.shenyu.common.exception.ShenyuException;
import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.common.utils.Singleton;
import org.apache.shenyu.plugin.motan.cache.ApplicationConfigCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +41,13 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
/**
* Motan proxy service.
@@ -46,10 +56,14 @@ public class MotanProxyService {
private static final Logger LOG =
LoggerFactory.getLogger(MotanProxyService.class);
+ private final ThreadFactory factory =
ShenyuThreadFactory.create("shenyu-motan", true);
+
+ private ExecutorService threadPool;
+
/**
* Generic invoker object.
*
- * @param body the body
+ * @param body the body
* @param metaData the meta data
* @param exchange the exchange
* @return the object
@@ -88,8 +102,20 @@ public class MotanProxyService {
return null;
}
//CHECKSTYLE:ON IllegalCatch
- ResponseFuture finalResponseFuture = responseFuture;
- CompletableFuture<Object> future =
CompletableFuture.supplyAsync(finalResponseFuture::getValue);
+ if (Objects.isNull(threadPool)) {
+ MotanRegisterConfig config =
Singleton.INST.get(MotanRegisterConfig.class);
+ if (Objects.isNull(config)) {
+ // should not execute to here
+ threadPool = Executors.newCachedThreadPool(factory);
+ } else {
+ int corePoolSize =
Optional.ofNullable(config.getCorethreads()).orElse(0);
+ int maximumPoolSize =
Optional.ofNullable(config.getThreads()).orElse(Integer.MAX_VALUE);
+ int queueSize =
Optional.ofNullable(config.getThreads()).orElse(0);
+ threadPool = new ThreadPoolExecutor(corePoolSize,
maximumPoolSize, 60L, TimeUnit.SECONDS,
+ queueSize > 0 ? new LinkedBlockingQueue<>(queueSize) :
new SynchronousQueue<>(), factory);
+ }
+ }
+ CompletableFuture<Object> future =
CompletableFuture.supplyAsync(responseFuture::getValue, threadPool);
return Mono.fromFuture(future.thenApply(ret -> {
if (Objects.isNull(ret)) {
ret = Constants.MOTAN_RPC_RESULT_EMPTY;