diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java index d347e058..77f54a4a 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java @@ -47,7 +47,7 @@ public abstract class AbstractServerPredicate implements Predicate private final Random random = new Random(); - private final AtomicInteger nextIndex = new AtomicInteger(); + private final AtomicInteger index = new AtomicInteger(0); private final Predicate serverOnlyPredicate = new Predicate() { @Override @@ -147,10 +147,10 @@ public List getEligibleServers(List servers, Object loadBalancer */ private int incrementAndGetModulo(int modulo) { for (;;) { - int current = nextIndex.get(); + int current = index.get(); int next = (current + 1) % modulo; - if (nextIndex.compareAndSet(current, next) && current < modulo) - return current; + if(index.compareAndSet(current,next)) + return next; } }