You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by xi...@apache.org on 2024/07/09 01:58:09 UTC
(dolphinscheduler) branch dev updated: Use SecureRandom rather than ThreadLocalRandom (#16291)
This is an automated email from the ASF dual-hosted git repository.
xincheng pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new fb8f3edc5a Use SecureRandom rather than ThreadLocalRandom (#16291)
fb8f3edc5a is described below
commit fb8f3edc5adaa42a48389895f3a16a173495e935
Author: Wenjun Ruan <we...@apache.org>
AuthorDate: Tue Jul 9 09:58:03 2024 +0800
Use SecureRandom rather than ThreadLocalRandom (#16291)
---
.../master/cluster/loadbalancer/RandomWorkerLoadBalancer.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/loadbalancer/RandomWorkerLoadBalancer.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/loadbalancer/RandomWorkerLoadBalancer.java
index df0d074b7c..4d348bd1ea 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/loadbalancer/RandomWorkerLoadBalancer.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/loadbalancer/RandomWorkerLoadBalancer.java
@@ -21,9 +21,9 @@ import org.apache.dolphinscheduler.server.master.cluster.WorkerClusters;
import org.apache.commons.collections4.CollectionUtils;
+import java.security.SecureRandom;
import java.util.List;
import java.util.Optional;
-import java.util.concurrent.ThreadLocalRandom;
import org.jetbrains.annotations.NotNull;
@@ -34,8 +34,11 @@ public class RandomWorkerLoadBalancer implements IWorkerLoadBalancer {
private final WorkerClusters workerClusters;
+ private final SecureRandom secureRandom;
+
public RandomWorkerLoadBalancer(WorkerClusters workerClusters) {
this.workerClusters = workerClusters;
+ this.secureRandom = new SecureRandom();
}
@Override
@@ -44,7 +47,7 @@ public class RandomWorkerLoadBalancer implements IWorkerLoadBalancer {
if (CollectionUtils.isEmpty(workerServerAddresses)) {
return Optional.empty();
}
- int index = ThreadLocalRandom.current().nextInt(workerServerAddresses.size());
+ int index = secureRandom.nextInt(workerServerAddresses.size());
return Optional.of(workerServerAddresses.get(index));
}