Class PortFactory


  • public class PortFactory
    extends Object
    Author:
    jamesdbloom
    • Constructor Detail

      • PortFactory

        public PortFactory()
    • Method Detail

      • findFreePort

        public static int findFreePort()
      • findFreePorts

        public static int[] findFreePorts​(int count)
        Find multiple free ports. Ports are selected from a larger pool of recently-available ports to reduce the chance of collisions. Callers should handle BindException as the returned ports may be claimed by another process before the caller binds them.
        Parameters:
        count - the number of free ports to find (must be between 1 and 1000 inclusive)
        Returns:
        an array of count distinct port numbers that were recently free
        Throws:
        IllegalArgumentException - if count is not between 1 and 1000