update load balancer directory name

This commit is contained in:
Ashish Pratap Singh
2024-06-01 23:13:41 -07:00
parent 180cacd49e
commit 851eb4bf39
10 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class RoundRobin {
private List<String> servers;
private AtomicInteger index;
public RoundRobin(List<String> servers) {
this.servers = servers;
this.index = new AtomicInteger(-1);
}
public String getNextServer() {
int currentIndex = index.incrementAndGet() % servers.size();
return servers.get(currentIndex);
}
public static void main(String[] args) {
List<String> servers = List.of("Server1", "Server2", "Server3");
RoundRobin roundRobinLB = new RoundRobin(servers);
for (int i = 0; i < 6; i++) {
System.out.println(roundRobinLB.getNextServer());
}
}
}