private static void usage(String s) {
    err.println("\n** " + s + "\n");
    err.println("usage: java AvailablePort socket|jgroups [\"addr\" network-address] [port]");
    err.println();
    err.println(
        "This program either prints whether or not a port is available for a given protocol, "
            + "or it prints out an available port for a given protocol.");
    err.println();
    System.exit(1);
  }
Once you call this the socket will be freed and can then be reallocated by someone else.
geode-membership/src/main/java/org/apache/geode/internal/membership/utils/AvailablePort.java