code: public static int getFreePort(int defaultPort) throws IOException {
      try (
          ServerSocket serverSocket = new ServerSocket(defaultPort)
      ) {
        return serverSocket.getLocalPort();
      } catch (IOException e) {
        return getFreePort();
      }
    }
docs: 查看指定的端口号是否空闲，若空闲则返回否则返回一个随机的空闲端口号