void checkPort ( int port , String msg ) { StringBuilder message = new StringBuilder ( ) . append ( " " ) . append ( msg ) ; String portInUseError = String . format ( "Port %d is already in use. Please shutdown the service " + "listening on this port or configure a different port%s." , port , message ) ; boolean free = false ; try { free = PortProber . pollPort ( port ) ; } catch ( RuntimeException e ) { throw new IllegalArgumentException ( portInUseError , e ) ; } finally { if ( ! free ) { throw new IllegalArgumentException ( portInUseError ) ; } } }
Check the port availability