Class ConnectionManager { Queue<Connection> availableConnection; List <Connection> allotedConnection; ConnectionManager( Integer noOfConnections, ConnectionPoperties props ) { //Create the no of connection objects and assign to avaialbleConnection } Conection getConnection() { syncronized( this.class) { if (availableConnection.isEmpty() ) { throw ConnectionExhausted(); } conn = availableCOnnection.poll(); alottledConectiion.add(conn); } return conn; } synchronized Conection releaseConnection(Connection conn) { alottedconnection.remove(conn); avaialbleConection.add(conn); }
Collection of Interview Question on Data structure, Algorithm, Java, C++ and more