Please review this connection pool. I tested it and it works but can we improve it from design or performance perspective?
public class ConnectionPool {
private static final int MAX_SIZE=10;
private static final BlockingQueue<Connection> bq;
static{
bq= new ArrayBlockingQueue<Connection>(MAX_SIZE);
for(int i=0;i<MAX_SIZE;i++)
{
try {
bq.add(makeConnection());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("total size:" + bq.size());
}
public static Connection getConnection() throws InterruptedException
{
System.out.println("size before getting connection"+ bq.size());
Connection con=bq.take();
System.out.println("size after getting connection"+ bq.size());
return (con);
}
public static boolean releaseConnection(Connection con) throws InterruptedException
{
System.out.println("size before releasing connection"+ bq.size());
boolean bool =bq.add(con);
System.out.println("size after releasing connection"+ bq.size());
return (bool);
}
public static Connection makeConnection() throws SQLException {
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", "root");
connectionProps.put("password", "java33");
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn = DriverManager.getConnection("jdbc:" + "mysql" + "://"
+ "localhost" + ":" + "3306" + "/test", connectionProps);
System.out.println("Connected to database");
return conn;
}
}