What is the problem in my Connection Pool ???

Hello,guys:
My using connection pool is in trouble,it always dies and does't output any error messages(can not get an available connection),so I should restart my Tomcat(4.1),
The following code in Login.jsp page initializes the pool :
<%
     ConnectionPool cp = ConnectionPool.getInstance();
     try{
          if(cp.pool == null){
               cp.initialize(50,5000);
               System.out.println("Pool hava been initilized");
     catch(Exception e){
          System.out.println("ERROR:"+e);
%>and,call the following code in other JSPs and Servlets to use a connection got from the pool
ConenctionPool cp = ConnectionPool.getInstance();  // get an instance of ConnectionPool
Connection con = cp.getConnection();               //get a connection
Statement stmt = con.createStatement();           
stmt.close();                                     
cp.releaseConnection(con);                         //release the connection and push to the pool-----start of ConnectionPool.java----------
package mrp.util;
import java.util.Stack;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.util.Enumeration;
public final class ConnectionPool {
    public Stack pool;
    private long timeout;
    private static ConnectionPool mySelf;
    private Connection con;
    private ConnectionPool() {
    public static ConnectionPool getInstance(){
     if(mySelf == null){
         mySelf = new ConnectionPool();
     return mySelf;
    public synchronized void initialize(int numCons,long timeout) throws SQLException{
     if(pool != null){
         throw new SQLException ("Pool already initialized");
     try{
         this.timeout = timeout;
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         pool = new Stack();
         for(int i=0 ; i < numCons;i++){
          pool.push(DriverManager.getConnection("jdbc:odbc:MRPII","sa","112233"));
     catch(ClassNotFoundException ex){
         throw new SQLException("Driver not found!!!");
    public synchronized Connection getConnection() throws SQLException{
     if(pool == null){
         throw new SQLException ("Pool not initialized");
     while(pool.empty()){
         try{
          wait(timeout);
         catch(InterruptedException ex){
          throw new SQLException ("Connection not available");
     con = (Connection) pool.pop();
     return con;
    public synchronized void releaseConnection(Connection con) throws SQLException {
     if(pool == null){
         throw new SQLException ("Pool not initialized");
     pool.push(con);
     notifyAll();
    public synchronized int getConnectionCount() throws Exception{
     return pool.size();
    public void destroyPool() throws SQLException {
     if(pool == null){
         throw new SQLException("Pool not initialized");
     while(!pool.empty()){
         ((Connection)pool.pop()).close();
         pool = null;
}-----End of ConnectionPool.java----------
Any suggestions? Thanks

a) call notifyAll after you finish initialize
instad you may wish to use your own releaseConnection per connection. so getConnection will work after one connection...
b)
for(int i=0 ; i < numCons;i++){
releaseConnection(DriverManager.getConnection("jdbc:odbc:MRPII","sa","112233"));
c) use an single instance rather than a static myPool. it will avoid confusion between the static and instance lock.
d) use a private constructor
d) call the initialize from getInstance() for sake. too much client code.

Similar Messages

Maybe you are looking for

  • Is there an jdev ARCS (appl. revision control system) extension available ?

    Is there an ARCS ( application revision control system ) extension available for Jdeveloper ? Googling took me to OAF developer guide which said - "With the ARCS (Applications Revision Control System) Extension for JDeveloper, you can perform most so

  • Connecting webcam hd-3310 to a smart tv

    Is it possible to connect an HP Webcam HD-3310 to a Samsung Smart TV and get the camera to work off of the TV? I know this model of webcam is not supported on all TVs. Thanks,

  • Generate an event

    Hi all, I have a class that has a function that takes time to perform. This function reads data from a text file into an array. I need to notify the caller when the data is actually read so he may use another class member function to get them. Please

  • Unable to upgrade some songs to iTunes plus

    Hello - I've seen some other discussions on this topic so I guess it's not an uncommon problem, but I wanted to ask about it anyway in case there are new insights about how to fix it! I have about 75 old "Protected AAC" songs - 128 bps DRM-protected

  • I need to update it on mcAfee but to do it i have to close the program but it doesent close

    I need to update skype on McAfee but to do so I have to close skype but skype stays open all the time and i cant close it Help please!