File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes disable connection caching -> DriverManager Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "disable connection caching -> DriverManager" Watch "disable connection caching -> DriverManager" New topic

disable connection caching -> DriverManager

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308

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 ]

aldana software engineering blog & .more
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
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

Joined: Dec 29, 2005
Posts: 308
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.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: disable connection caching -> DriverManager
It's not a secret anymore!