Re: Help Needed with Connection Pooling for Java Swing Based

From: Barry Lind <blind(at)xythos(dot)com>
To: Shanmugasundaram Doraisamy <shan(at)ceedees(dot)com>
Cc: postgresql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Help Needed with Connection Pooling for Java Swing Based
Date: 2003-03-26 20:58:59
Message-ID: 3E821493.30403@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I just ran your test case and everything seems to be working correctly
as far as I can tell. The program creates one and only one connection
to the database. I don't see multiple connections created as you are
reporting.

I don't know anything about swing, but it is clear that the code for
swing you have below isn't correct. Because with this swing call the
program doesn't exit. It seems the swing code is starting some other
threads that are running and thus the main program doesn't exit until
those threads stop running (and I don't know what swing calls are
necessary to stop the swing threads from running).

So with the swing call in place I have to ctrl-C to stop the app from
running, but from the jdbc side of things everything seems to be working
correctly.

Perhaps I don't understand the problem you are seeing?

thanks,
--Barry

Shanmugasundaram Doraisamy wrote:
> 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
> ##########################################################################################
>
> ###########################################################################################
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Derek S 2003-03-26 21:44:38 Re: Help Needed with Connection Pooling for Java Swing Based
Previous Message Scot P. Floess 2003-03-26 20:08:03 Re: : URGENT: problem installing Ant