Citigroup Interview Question for Financial Software Developers

Country: United States

Comment hidden because of low score. Click to expand.
of 1 vote

Below is the connection pooling at the most basic level(for database connections ). One can easily put pool size and time out in it. To give the user the flexibility to use close method on connection we will have to provide a wrapper for connection and implement several methods.

package connection_pooling;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.LinkedList;
import java.util.List;

public class MyConnectionPool {

	static List<Connection> pool;
		pool=new LinkedList<Connection>();
		for (int i = 0; i < 5; i++) {
			Connection connection = null;
			connection = DriverManager.getConnection("jdbc:postgresql://", "userName","Password");
			}catch(Exception e){
	public static Connection getConnection(){

			return pool.remove(pool.size()-1);
			throw new Error("no conn available");
	public static void returnConnection(Connection conn){
	public static void main(String[] args) {
		Connection conn = MyConnectionPool.getConnection();
		//do something

- praveenkcs28 April 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

One thing to remember when writing connection-pools: never pass the raw connection to your caller. Put it in a wrapper object that has no-ops for calls like close() //connection, so that the raw connection is protected, and pass it via interface. When a connectionWrapper is returned by user, put the raw connection back in your pool, but also null out the reference from the wrapper to the raw-connection. Also good idea would be to rollback any uncommited transactions on the raw connection before putting it in pool

- Amit January 24, 2017 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More