commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geronimo M. H." <geronimo...@arcor.de>
Subject Re: [dbcp] need help for late configuration in multithreaded environment
Date Thu, 15 Apr 2010 03:20:49 GMT
Phil Steitz wrote:
> Geronimo M. H. wrote:
> > Hello,
> >
> > I changed my db-access to be user-configurable. When my app starts, it
> > reads the archive-name and driver class, the user configured and tries to
> > setup a poolable datasource from that properties.
> >
> > I'm now trapped within threads, context initialization and timings.
> >
> > The point is, when I read the user properties, that should be used for
> > datasource, the datasource instance has already been created (by the
> > context). When I load the drivers jar and class, all works well, but as
> > soon as I ask a connection from the datasource, I get an exception, which
> > says, that the driver-class could not be loaded.
> >
> > So I guess, the point is, that both actions run in different threads and
> > I don't know, how to change the classloader of an already loaded instance
> > or an unknown thread.
> >
> > Can anybody shine me a light please on what datasource to use or how to
> > change properties of an already instantiated datasource?
>
> Sorry for the slow response.  

No prob. Thank you for your attention and support!

> If I understand your problem 
> correctly, you need to get the datasource fully initialized
> (including loading the driver) when you first create it.

No, that's not my problem. I'd like late initialization, but it looks like the 
datasource does early initialization.

My problem is, that at time of creation of the DataSource, the jarfile of the 
JDBC-Driver is not known and not added to the classpath yet. So the created 
DataSource has an invalid or empty driver.

When my application code comes into play, the datasource has already been 
referenced, so I can't create another one - I have to (re-)configure the 
existing instance.

I tried to write a DataSourceFactory, but the springframework can't resolve it 
and claims at factory-creation time, that the datasource is already in 
creation process (most probabely an error of springframework).

> If you are using the most recent release of dbcp (1.3 for jdk 1.4, 1.5 or
> 1.4 > for jdk 1.6), and you use BasicDataSourceFactory to create the
> BasicDataSource, specifying an initialsize > 0 will cause
> initialization to happen at BasicDataSource creation time.

I use 1.4 for jdk 1.6 - and I tried BasicDataSource. But when the classloader 
is determined and put into the BasicDataSource, it has been already 
initialized and the classloader is not used. The first request to 
getConnection of the DataSource happens after the setting of the 
classloader - and the jdbc-access fails with "unknown driver" although the 
driver has been loaded successfully.

... so I tried the sample-code from ManualPoolingDataSource - but that fails 
of the limitations of the springframework, so it looks like I have to kick 
off springframework and write my own context-handling (a task, which I'd 
prefer to avoid).

kind regards

Geronimo

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message