Skip to content

Commit ae97cc0

Browse files
authored
fix (#1346)
1 parent bc6f079 commit ae97cc0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/reactive/DiscoveryClientBasedReactiveLoadBalancer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,8 @@
1717
package org.springframework.cloud.client.loadbalancer.reactive;
1818

1919
import java.util.List;
20-
import java.util.Random;
20+
import java.util.random.RandomGenerator;
21+
import java.util.random.RandomGeneratorFactory;
2122

2223
import org.reactivestreams.Publisher;
2324
import reactor.core.publisher.Mono;
@@ -38,7 +39,7 @@
3839
*/
3940
class DiscoveryClientBasedReactiveLoadBalancer implements ReactiveLoadBalancer<ServiceInstance> {
4041

41-
private final Random random = new Random();
42+
private final RandomGenerator random = RandomGeneratorFactory.getDefault().create();
4243

4344
private final String serviceId;
4445

@@ -52,10 +53,10 @@ class DiscoveryClientBasedReactiveLoadBalancer implements ReactiveLoadBalancer<S
5253
@Override
5354
public Publisher<Response<ServiceInstance>> choose() {
5455
List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
55-
if (instances.size() == 0) {
56+
if (instances.isEmpty()) {
5657
return Mono.just(new EmptyResponse());
5758
}
58-
int instanceIdx = this.random.nextInt(instances.size());
59+
int instanceIdx = random.nextInt(instances.size());
5960
return Mono.just(new DefaultResponse(instances.get(instanceIdx)));
6061
}
6162

@@ -72,10 +73,10 @@ public Publisher<Response<ServiceInstance>> choose(Request request) {
7273
}
7374
}
7475
}
75-
if (instances.size() == 0) {
76+
if (instances.isEmpty()) {
7677
return Mono.just(new EmptyResponse());
7778
}
78-
int instanceIdx = this.random.nextInt(instances.size());
79+
int instanceIdx = random.nextInt(instances.size());
7980
return Mono.just(new DefaultResponse(instances.get(instanceIdx)));
8081
}
8182

0 commit comments

Comments
 (0)