Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disable connection caching -> DriverManager

 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

I am running an local app with MySQL and want to show in a lecture, how to profile a java app.

Here my profiling case study:
1)running app, which does not cache db-connections: ->very slow.
2)identify with profiler, that getting a connection from "scratch" every sql-statement does take so long.
3) look at code and identify bottleneck, that connection does not get cached
4) changing code, so it does use caching
5)run profiler and proof that app is much quicker
6)profiling successfull!

now my problem:
-DriverManager seems to cache connections (which is senseful of course), but in my case, how is it possible to disable this caching/connection-pooling?
-If disabling caching of DriverManager is not possible, any suggestions how to do this another way?

thanks a lot!
[ January 05, 2006: Message edited by: manuel aldana ]
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.DriverManager does not cache connections. That would violate what happens when you call close on a Connection object among other things.

It might be faster because once the Driver is registered the first time you do not have to go through the steps of loading the Driver class and registering it with the DriverManager each time. With that in mind you might want to deregister the driver to demonstrate that.

But absolutely 100% sure I promise you the DriverManager is not cacheing connections. You can look through the source for DriverManager yourself if you wish to see this.

Another possibility is that the driver itself is cacheing a connection or connection information. But as that would be the driver doing that you would have to consult the driver docs to find out more about that.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, after a while i found out too, that DriverManager is not caching.
I was just a little bit confused, because i realized (with JProbe) that app just slowed down a bit, though i called getConnection() with close() 40 times (no caching) instead of 1 time (cached connection as instance-field). and the first time calling getConnection() took by far the most time.

as you said the long time for the first connection-retrieval must have been due to class-loading issues.

thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic