Browse Source

Use SecureRandom rather than ThreadLocalRandom (#16291)

dev
Wenjun Ruan 6 months ago committed by GitHub
parent
commit
fb8f3edc5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/loadbalancer/RandomWorkerLoadBalancer.java

7
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));
}

Loading…
Cancel
Save