How to randomly select the ip of a machine

  • 2020-05-09 19:09:07
  • OfStack

String ipArr[]={"127.0.0.1","127.0.0.2"};
          int iRandom = new Random().nextInt(ipArr.length)%(ipArr.length); // random Numbers of 0 and 1
              String ip =ipArr[iRandom];
              System.out.println(ip);
This method can be used when load balancing is required, that is, when you want to select multiple machines for processor execution. Randomly select 1 machine to process.

The ip address can be configured in the database.

This is true for both activation and business testing.


Related articles: