avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paulo Gaspar" <paulo.gas...@krankikom.de>
Subject RE: [Design] ContainerManager is under fire--let's find the best resolution
Date Mon, 17 Jun 2002 10:44:07 GMT
> So there is absolutely no reason at all to have to request/release
> the component on every iteration--saving yourself allot of expensive
> processing on the ECM.

Hi Berin,


That is ALMOST just like that.

In my framework the component returned by the CM lookup() to access a
database is a DataSource, but that DataSource still needs to be 
released after processing a "request".

Of course that this "special" DataSource tracks which Connections are
still open and closes them on release. This is the only way to keep 
really safe from resource leak situations possibly caused by bad user 
code (e.g.: bad excaption handling)... and that is one of the targets
of using IoC, isn't it?


Have fun,
Paulo Gaspar


> -----Original Message-----
> From: Berin Loritsch [mailto:bloritsch@apache.org]
> Sent: Friday, June 07, 2002 3:50 PM
> 
> 
> > From: Vadim Gritsenko [mailto:vadim.gritsenko@verizon.net] 
> > > 
> > > What's wrong with this:
> > > 
> > > public void do () {
> > >   for (int I = 0; i < 8000; i++) {
> > >     mycomp = lookup (...);
> > >     info = mycomp.getIt(i);
> > >     release(mycomp);
> > > 
> > >     info = calculate(info);
> > >     print(info);
> > >   }
> > > }
> > > 
> > > Assumptions: mycomp.getIt() might use JDBC connection which are
> > limited in
> > > count, and calculate() takes some time, so it is really not wise to
> > block
> > > connection for time of the whole loop.
> > > 
> > > 
> > > Vadim
> 
> 
> :)  Here is where the design I am advocating is already in use.  The
> DataSourceComponent is a ThreadSafe(!!!!) component that you use to
> get the connection.  The DataSourceComponent can safely be looked up
> and held on to for the life of the calling component.  No sweat.
> 
> So the other part of your example would be written:
> 
> public String getIt(int val)
> {
>     String answer;
>     Connection myConn = m_datasource.getConnection();
>     //    .......  All the DB logic
>     myConn.close();
> 
>     return answer;
> }
> 
> So there is absolutely no reason at all to have to request/release
> the component on every iteration--saving yourself allot of expensive
> processing on the ECM.
> 


--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message