package com.orientechnologies.orient.core.db;

public class OConnectionNext {
  private volatile int next = 0;
  private final int limit;

  public OConnectionNext(int limit) {
    this.limit = limit;
  }

  public synchronized int next() {
    if (next < limit) {
      next++;
    } else {
      next = 0;
    }
    return next;
  }
}

package com.orientechnologies.orient.core.db;

public class OConnectionNext {
  private volatile int next = 0;
  private final int limit;

  public OConnectionNext(int limit) {
    this.limit = limit;
  }

  public synchronized int next() {
    next++;
    if (next >= limit) {
      next = 0;
    }
    return next;
  }
}

make first round robing node select more reliable