LeastConnections never records active connections

Author: dajiaohuangCreated Sep 18, 2026Updated Sep 18, 2026

In implementations/java/load_balancing_algorithms/LeastConnections.java, getNextServer() only reads serverConnections and never increments the selected server's active-connection count. The class exposes releaseConnection(), but no matching acquire operation or increment on selection.\n\nReproduction:\n1. Compile the file with javac.\n2. Run its included main method.\n3. The output selects Server1 six times in a row, even though each iteration is intended to represent a new request.\n\nExpected behavior: selecting a server should be paired with an explicit acquire operation that increments its count, or the example should document and implement the required lifecycle. Otherwise the least-connections policy cannot distribute concurrent work based on active connections.\n\nThe same issue is reproducible by calling getNextServer() repeatedly without any other state mutation.

Source: ashishps1/awesome-system-design-resources