Java HTTP Port Find getFreePortNoSych()

Here you can find the source of getFreePortNoSych()

Description

Returns a free port

License

Apache License

Exception

Parameter Description
Exception Any exception

Return

The free port

Declaration

protected static int getFreePortNoSych() throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.ServerSocket;

public class Main {
    /**//www.  j av  a  2 s  .co m
     * Returns a free port
     * 
     * @return   The free port
     * @throws   Exception
     *          Any exception
     */
    protected static int getFreePortNoSych() throws Exception {
        ServerSocket socket = new ServerSocket(0);
        int port = socket.getLocalPort();
        socket.close();

        return port;
    }
}

Related

  1. getFreePort()
  2. getFreePort()
  3. getFreePort()
  4. getFreePort(int port)
  5. getFreePort(int pPort)
  6. getFreePortNumber(int defaultPortNumber)
  7. getFreeServerPort(int port)
  8. getImportedXmlSchemaPath(String namespace, String portType, String operation)
  9. getNextAvailable(int port)