Re: When and where to close the connection in a struts-web-application?

Per Nyfelt <[email protected]>
Newsgroups gmane.comp.java.ozone.user
Organization Resourcing Networks
Message-ID <[email protected]>
Hi Roy,

Opening this many database connections is most likely an error in the 
application using Ozone. I assume you are getting the error on the client 
side? Everytime open database is called a new object in created and this is 
why you will eventually run out of memory if you keep references to the db's 
and create many of them by opening enough connections. What would you like 
ExternalDatabase to do? Refuse you the connection because you've created too 
many or reuse an old existing one that points to the same target?

Regards,
Per

måndagen den 8 mars 2004 18.46 skrev Roy Ladner:
> I've notice that when the database connection is not closed, the number
> of open connections continues to grow  as
> ExternalDatabase.openDatabase(...) is repeatedly called until an out of
> memory error occurs.  Is this an operator error or is there an issue in
> the Ozone code that should be addressed?
>
> Per Nyfelt wrote:
> >Hi Arjen,
> >
> >Use application scope (or equivalent) instead of session.
> >
> >ExternalDatabase handles pooling and simultaneous access in itself. See
> > FAQ for more details.
> >
> >Best regards,
> >Per
> >
> >måndagen den 8 mars 2004 17.52 skrev Arjen van der Meijden:
> >>Hi list,
> >>
> >>I'm building a web application with Struts and it uses ozone as its
> >>backend database. Well thats easily done and what I have works quite
> >> nice.
> >>
> >>There is one problem however I don't know where or when to close the
> >>connection to the ozone database. I can easily open one as soon as I
> >>need some data, but that data will be put into the "request scope" and
> >>then the Struts-ActionServlet forwards the control to some jsp-file (or
> >>another Action).
> >>
> >>So what I do now is something like:
> >>public ... execute(...)
> >>{
> >>   ExternalDatabase db = ExternalDatabase.openDatabase(...);
> >>   Object someObject = db.objectForName("someName");
> >>
> >>   request.setAttribute("someObject", someObject);
> >>   return actionMapping.findForward("success");
> >>}
> >>
> >>And the control gets forwarded to some jsp, that may do something like:
> >><jsp tags>
> >><bean:write name="someObject" property="someProperty" />
> >><some more jsp tags>
> >>
> >>And when the entire operation is done, the database-connection should be
> >>close()-ed. But at that time, I have no direct control over the
> >>operation anymore... and so the number of open connections increases at
> >>every pageview.
> >>
> >>I see a few solutions to this, but don't know which is best or even more
> >>exist:
> >>- Make a static singleton reference to an ExternalDatabase object; there
> >>won't be much connectionpooling anymore, but you can be certain there
> >>will be only one databaseconnection. It may perform quite badly because
> >>there won't be multiple connections available at any time?
> >>
> >>- Make some kind of value objects, create value objects via the proxies
> >>and close the connection as soon as the value objects are created and
> >>stored in the request-scope. This really doesn't have my preference,
> >>even though it may be saver and "better" in the application design (it
> >>is also much more work).
> >>
> >>Thanks in advance and best regards,
> >>
> >>Arjen
> >>
> >>
> >>PS, John Dixon, I forgot to thank you for your advise/answer on my
> >>previous e-mail.
> >>
> >>
> >>
> >>
> >>-------------------------------------------------------
> >>This SF.Net email is sponsored by: IBM Linux Tutorials
> >>Free Linux tutorial presented by Daniel Robbins, President and CEO of
> >>GenToo technologies. Learn everything from fundamentals to system
> >>administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> >>_______________________________________________
> >>Ozone-users mailing list
> >>[email protected]
> >>https://lists.sourceforge.net/lists/listinfo/ozone-users
> >
> >-------------------------------------------------------
> >This SF.Net email is sponsored by: IBM Linux Tutorials
> >Free Linux tutorial presented by Daniel Robbins, President and CEO of
> >GenToo technologies. Learn everything from fundamentals to system
> >administration.http://ads.osdn.com/?ad_id70&alloc_id638&opÌk
> >_______________________________________________
> >Ozone-users mailing list
> >[email protected]
> >https://lists.sourceforge.net/lists/listinfo/ozone-users



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.