1
votes

I am doing jndi lookup for datasource configured in JBOSS AS.Code for which is as below.

initialContext = new InitialContext(props);

dataSource = (DataSource)initialContext.lookup(bundle.getString("jndiName"));

connection = dataSource.getConnection();

This snippet of code is placed in doPost of servlet. Also i am safely calling

connection.close()

after using connection object.

My datasource config has following entries

<min-pool-size>1</min-pool-size>
<max-pool-size>1</max-pool-size>

As per my understanding of connection pooling, each time i make a request to servlet same connection object is returned by datasource .getConnection() call(Since i have specified min and max pool size to be 1 and a call to close does not close the DB connection altogether).

Now how do i verify that same connection object is being returned?

1
Why do you want to verify the connection object? One way to cache the object locally and then check against the cached values.Arun P Johny
Just to be sure that connection is not being created to DB everytime. I found no way to check whether pooling is enabled or disabledVinay thallam
1 way is to check the database server to see how many connections are created.Arun P Johny
As a connection pool maintains physical connections and hands out a (usually new) logical connection (either a Proxy or a custom Connection implementation) for each request, there is no way to verify it is the exact same Connection without resorting to reflection or DataSource or database specific tricks to verify the identity of the physical connectionMark Rotteveel
Thanks.. I checked my sql server by querying for number of open connections. Remains 1 (for my config setting) even after calling connection.close() and even after calling datasource.getConnection() second time.My problem is solved.Vinay thallam

1 Answers

0
votes

You actually can't be sure that it is the same connection. It maybe problems with connection with database, so another connection had to be created. Why you want to verify connection? Maybe you could save hash value and compare them?