• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need advice from a guru

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi:
I am new in using JDBC, but I think I have good understanding of how to create an destroy a connection using a connection pool and datasource.
Here is my situation:
The Database admin accusing me of not writing good code. He says that my code leaves database connections open. I close all my connections proporly in a finally clause. I ran a simulator accessing the database and excuting a SQL statement. I ran the simulatore on Tomcat accessing SQL server 2k. The simulator run in 5 windows, 5 users, with 10000 connections per user. Total of 50000 times of opening, excuting a query, and then closing a connection.
After the simulation stoped, and after the connection idle time out past, he could see from his side that there are about 3 or 4 connections open. The minimum number of connection on the server is 2. He is telling me that there are 1 or 2 connections are not closed.
I know there is nothing wrong with the code. Is it normal that some connection will still open? How can I answer his demands for closing all the connections?
I really appreciate any help.
 
Joe Ess
Bartender
Posts: 9318
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A connection pool keeps several connections open to avoid the overhead of creating and destroying them. when you "close" a connection from a connection pool, it isn't really closed, it is placed back in the pool for use at a later time. Depending on how your pool is implemented, it may create additional connections in order to handle a large load, and it may hold onto those connections as well. I think the connections the DBA is seeing are the ones that the connection pool is maintaining. If you really were creating connections and leaving them open (a "connection leak"), your DBA would have several thousand connections to look at. That is, if the database didn't crash first.
[ March 02, 2004: Message edited by: Joe Ess ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic