Re: When and where to close the connection in a struts-web-application?
Roy Ladner <[email protected]>
| Newsgroups | gmane.comp.java.ozone.user |
|---|---|
| Message-ID | <[email protected]> |
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
>
>
>
>
>
--
Dr. Roy Ladner
Naval Research Laboratory
Mapping, Charting & Geodesy Analysis Program
Building 1005, Room D-7A, Code 7440.2
Stennis Space Center, MS 39529
voice: (228) 688-4679
fax: (228) 688-4853
email: [email protected]
URL: http://dmap.nrlssc.navy.mil/dmap