All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ibole.infrastructure.common.utils.PortFactory Maven / Gradle / Ivy

The newest version!
package com.github.ibole.infrastructure.common.utils;

import java.net.ServerSocket;
import java.util.concurrent.TimeUnit;

/*********************************************************************************************
 * .
 * 
 * 
 * 

* Copyright 2016, iBole Inc. All rights reserved. * *********************************************************************************************/ public class PortFactory { public static int findFreePort() { int port; try { ServerSocket server = new ServerSocket(0); port = server.getLocalPort(); server.close(); // allow time for the socket to be released TimeUnit.MILLISECONDS.sleep(350); } catch (Exception e) { throw new RuntimeException("Exception while trying to find a free port", e); } return port; } public static void main(String[] args) { System.out.print(findFreePort()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy