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

Arjen van der Meijden <[email protected]>
Newsgroups gmane.comp.java.ozone.user
Message-ID <[email protected]>
Indeed that is what I noticed too. After playing around with ab -c 10 -n 
1000, I had "too many open files" and therefore noticed the below behaviour.

Anyway, I've created a PlugIn for struts which gets started as soon as 
my struts application starts and gets destroyed when struts is getting 
destroyed. And creates a database upon startup, close's it at the end 
and provides static accessors to the instance.

If anyone is interested in it, I can post it to this list.

Best regards,

Arjen


Roy Ladner wrote:

> 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_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.