@@ -127,7 +127,7 @@ public static void scanUnusedClient() {
127
127
} finally {
128
128
logger .warn ("RpcClient in clusterName={}, naming={}, remove rpc client{}, due to unused time > {} ms" ,
129
129
bConfig .getName (), bConfig .getNamingOptions ().getServiceNaming (),
130
- e .getProtocolConfig ().toSimpleString (), e . getProtocolConfig () .getIdleTimeout ());
130
+ e .getProtocolConfig ().toSimpleString (), bConfig .getIdleTimeout ());
131
131
}
132
132
}));
133
133
}
@@ -148,10 +148,14 @@ private static boolean isIdleTimeout(BackendConfig bConfig, RpcClientProxy clien
148
148
public static RpcClient getOrCreateClient (BackendConfig bConfig , ProtocolConfig pConfig ) {
149
149
Preconditions .checkNotNull (bConfig , "backendConfig can't not be null" );
150
150
Map <String , RpcClientProxy > map = CLUSTER_MAP .computeIfAbsent (bConfig , k -> new ConcurrentHashMap <>());
151
- RpcClientProxy rpcClientProxy = map .computeIfAbsent (pConfig .toUniqId (),
152
- uniqId -> createRpcClientProxy (pConfig ));
153
- rpcClientProxy .updateLastUsedNanos ();
154
- return rpcClientProxy ;
151
+ return map .compute (pConfig .toUniqId (),
152
+ (uniqId , client ) -> {
153
+ if (client == null ) {
154
+ client = createRpcClientProxy (pConfig );
155
+ }
156
+ client .updateLastUsedNanos ();
157
+ return client ;
158
+ });
155
159
}
156
160
157
161
private static RpcClientProxy createRpcClientProxy (ProtocolConfig protocolConfig ) {
@@ -252,7 +256,7 @@ private static class RpcClientProxy implements RpcClient {
252
256
253
257
private RpcClient delegate ;
254
258
255
- private long lastUsedNanos = System .nanoTime ();
259
+ private volatile long lastUsedNanos = System .nanoTime ();
256
260
257
261
RpcClientProxy (RpcClient delegate ) {
258
262
this .delegate = delegate ;
0 commit comments