MCPcopy Create free account
hub / github.com/grpc/grpc-java / pickUnusedPort

Method pickUnusedPort

benchmarks/src/main/java/io/grpc/benchmarks/Utils.java:292–301  ·  view source on GitHub ↗

Picks a port that is not used right at this moment. Warning: Not thread safe. May see "BindException: Address already in use: bind" if using the returned port to create a new server socket when other threads/processes are concurrently creating new sockets without a specific port.

()

Source from the content-addressed store, hash-verified

290 * creating new sockets without a specific port.
291 */
292 public static int pickUnusedPort() {
293 try {
294 ServerSocket serverSocket = new ServerSocket(0);
295 int port = serverSocket.getLocalPort();
296 serverSocket.close();
297 return port;
298 } catch (IOException e) {
299 throw new RuntimeException(e);
300 }
301 }
302}

Callers 6

setUpMethod · 0.95
setUpMethod · 0.95
setupMethod · 0.95
setServerValueMethod · 0.95
LoadServerMethod · 0.95
setUpMethod · 0.45

Calls 2

getLocalPortMethod · 0.80
closeMethod · 0.65

Tested by 3

setUpMethod · 0.76
setUpMethod · 0.76
setupMethod · 0.76