Hi All, Got the following information from a book - "The DriverManager associates each registered JDBC driver with the class loader of the class which registered the driver, so that the JDBC drivers available to an application are only the ones which have been loaded by the same class loader." Why should an application be able to see the drivers loaded by the same class loader ? Thanks
I'm not sure either, but if I understand what you're saying, then you have it backwards. A ClassLoader will only be associated with a single application, but an application can have multiple ClassLoaders. It is also possible to load a single Class multiple times in an application, depending on how many ClassLoaders you have and how they are configured. Finally, this allows a single Class to have the same database Driver multiple times in a single application. I can't quite see the point off the top of my head, but I'm sure there must be a reason. (As a complete guess, it might have to do with the fact that the DriverManager acts as a Singleton Pattern, but this is only supported by its ClassLoader, therefore the registration of Drivers must also be supported by ClassLoaders. Otherwise it might be possible for two DriverManagers to exist, and have a Class expect the Driver to be loaded even though the Driver was loaded against a DriverManager on a different ClassLoader. Or something) Dave
Joined: Mar 20, 2003
Hi David, Your reply created a basic question in my mind - If an application has multiple class loaders, is it possible to have multiple instances of a static class ?
It is more likely to occur as a result of a distributed application or an application running on an application server (which use multiple ClassLoader tricks), but sure, I can't see why not. The usual behaviour of a ClassLoader is to test to see if its 'parent' has loaded a class before trying to load it again. However, two ClassLoaders with the same parent can both load the same class if the parent hasn't loaded it. Also, Application Servers short circuit the the 'load from parent' rule so that in some cases it doesn't happen. This allows the app servers to use ClassLoaders as the boundaries between multiple applications running on them. And we're way off topic
subject: Why should an application be able to see the drivers loaded by the same class loader