Help Needed with Connection Pooling for Java Swing Based applications - reg. - Mailing list pgsql-jdbc

From Shanmugasundaram Doraisamy
Subject Help Needed with Connection Pooling for Java Swing Based applications - reg.
Date
Msg-id 1048665685.13218.8.camel@vpsd2.ceedees.com
Whole thread Raw
Responses Re: Help Needed with Connection Pooling for Java Swing Based
List pgsql-jdbc
Dear group,

We are having some problems when using JDBC Connection Pool using
Postgrsql Jdbc3PoolingDataSource.

The Pool behaves fine if there is no Swing Component in the Program.
If there is a swing Component ,then the connection seems to be not
returning to the pool and calling for an additional instance of the
class leeds to the creation of fresh Connection objects ,at times it
even exceeds the maximum number allowed in the pool.
If we go for System.exit(0);(Killing) then only the Connection is returned .

But if we comment the swing component line (here in the attached Program
a JOptionPane is Used) then the pool behaves fine.


Herewith Iam attaching a Program which is behaving as detailed.

Any Help is Welcome.

##################################################################


##################################################################

/*
 * ConPool.java
 *
 * Created on 26 March 2003, 11:54
 */

/**
 *
 * @author  naks from vpsd,Erode
 *
 */
import org.postgresql.jdbc3.*;
import java.sql.*;

public class ConPool {

    Jdbc3PoolingDataSource source = null;
    private Connection conn = null;

    /** Creates a new instance of ConPool */
    public ConPool() {

    }

    /** Setting the Pool which intializes the Pool to 2. */
    public void setPool() {
        // DataSource initialization
        System.out.println("setPool()");
        try {
            System.out.println("setting pool");
            // constructs a pool only when source is not assigned.
            // this will prevent problems if the same pool is set more than
            // one time
            if (source == null) {
                source = new Jdbc3PoolingDataSource();
                // DataSource configuration.

        source.setServerName("192.168.0.51");
        source.setDatabaseName("kec_test_pool");
        source.setUser("venbro");
        source.setPassword("venbro");
        source.setMaxConnections(2);


            } else {
                System.out.println("pool is set");
                return;
            }
        } catch (Exception loException) {
            // logger.logToFile(loException);
            loException.printStackTrace();
        }

    } //End of setPool method


    /**
     * Method inserts data to a table "test" which is like
     * create table test (param1 varchar(2),param2 varchar(2)) ;

     */
     public int insertDatas(){

     int count=-1;


      try{

      conn=source.getConnection();

      PreparedStatement st = conn.prepareStatement("INSERT INTO test
values('P1','P2')");

      count = st.executeUpdate();

      st.close();

      conn.commit();
      conn.close();

    }
    catch (SQLException ex) {
       count=0;
      ex.printStackTrace();
    }

    return count;
    }//End of Insert Method


      public static void main(String args[]){


        ConPool cp=new ConPool();
        cp. setPool();
        int sucess_flag=cp.insertDatas();
        System.out.println("Sucess"+sucess_flag);

        /**
          * Upto this level the Connection pooling is working fine .
          * But if this Swing Component is added then it creates new
Connection
          * which is even more than the intial connection of the pool..
         *  We have to kill the application (System.exit(0))to remove
the Connection
         ** But on commenting line :105 "Swingline " the Pool is working
fine..

         */

javax.swing.JOptionPane.showMessageDialog(null,"VENBRO-ERODE","MESSAGE",1);//
Swing line 105



    }

}//End of the class
##########################################################################################

###########################################################################################


pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: Select For Update question
Next
From: Jean-Christian Imbeault
Date:
Subject: Re: Select For Update question