public static int getAvailablePort() {
        ServerSocket ss = null;
        try {
            ss = new ServerSocket();
            ss.bind(null);
            return ss.getLocalPort();
        } catch (IOException e) {
            return getRandomPort();
        } finally {
            if (ss != null) {
                try {
                    ss.close();
                } catch (IOException e) {
                }
            }
        }
    }
@author Robert HG (254963746@qq.com) on 7/23/14.
lts-core/src/main/java/com/github/ltsopensource/core/commons/utils/NetUtils.java