You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/30 03:15:29 UTC
[dubbo] branch 3.0 updated: perf: Improve the performance for
generating random numbers (#8167)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 9279c78 perf: Improve the performance for generating random numbers (#8167)
9279c78 is described below
commit 9279c786b16bddc28111532b5d7ebeed67a9874b
Author: Xiong, Pin <pi...@foxmail.com>
AuthorDate: Tue Jun 29 22:15:19 2021 -0500
perf: Improve the performance for generating random numbers (#8167)
---
.../apache/dubbo/rpc/cluster/router/mesh/route/MeshRuleRouter.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/route/MeshRuleRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/route/MeshRuleRouter.java
index 9a87c7a..2395d9d 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/route/MeshRuleRouter.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/route/MeshRuleRouter.java
@@ -42,7 +42,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
public class MeshRuleRouter implements Router, VsDestinationGroupRuleListener {
@@ -79,9 +79,7 @@ public class MeshRuleRouter implements Router, VsDestinationGroupRuleListener {
if (routeDestination == null) {
return invokers;
} else {
- Random random = new Random();
- int index = random.nextInt(routeDestination.size());
- DubboRouteDestination dubboRouteDestination = routeDestination.get(index);
+ DubboRouteDestination dubboRouteDestination = routeDestination.get(ThreadLocalRandom.current().nextInt(routeDestination.size()));
DubboDestination dubboDestination = dubboRouteDestination.getDestination();