Skip to content

Commit 10912c8

Browse files
CrazyHZMlixiaojiee
authored andcommitted
[Dubbo-3237]fix connectionMonitor in RestProtocol seems not work #3237 (#3455)
1 parent fa2316e commit 10912c8

File tree

1 file changed

+7
-6
lines changed
  • dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest

1 file changed

+7
-6
lines changed

dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class RestProtocol extends AbstractProxyProtocol {
6161

6262
private static final int HTTPCLIENTCONNECTIONMANAGER_MAXPERROUTE = 20;
6363
private static final int HTTPCLIENTCONNECTIONMANAGER_MAXTOTAL = 20;
64-
private static final int HTTPCLIENT_KEEPALIVEDURATION = 30*1000;
64+
private static final int HTTPCLIENT_KEEPALIVEDURATION = 30 * 1000;
6565
private static final int HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS = 1000;
6666
private static final int HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S = 30;
6767

@@ -70,7 +70,7 @@ public class RestProtocol extends AbstractProxyProtocol {
7070
private final RestServerFactory serverFactory = new RestServerFactory();
7171

7272
// TODO in the future maybe we can just use a single rest client and connection manager
73-
private final List<ResteasyClient> clients = Collections.synchronizedList(new LinkedList<ResteasyClient>());
73+
private final List<ResteasyClient> clients = Collections.synchronizedList(new LinkedList<>());
7474

7575
private volatile ConnectionMonitor connectionMonitor;
7676

@@ -136,16 +136,17 @@ public void run() {
136136

137137
@Override
138138
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
139-
if (connectionMonitor == null) {
140-
connectionMonitor = new ConnectionMonitor();
141-
}
142139

143140
// TODO more configs to add
144141
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
145142
// 20 is the default maxTotal of current PoolingClientConnectionManager
146143
connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXTOTAL));
147144
connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXPERROUTE));
148145

146+
if (connectionMonitor == null) {
147+
connectionMonitor = new ConnectionMonitor();
148+
connectionMonitor.start();
149+
}
149150
connectionMonitor.addConnectionManager(connectionManager);
150151
RequestConfig requestConfig = RequestConfig.custom()
151152
.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT))
@@ -239,7 +240,7 @@ public void destroy() {
239240

240241
protected String getContextPath(URL url) {
241242
String contextPath = url.getPath();
242-
return contextPath.endsWith("/") ? contextPath.substring(0,contextPath.length()-1) : contextPath;
243+
return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath;
243244
}
244245

245246
protected class ConnectionMonitor extends Thread {

0 commit comments

Comments
 (0)