Ben Dudley wrote:
> If I set a database connection in a bean with scope application how
> do I manage closing the connection and pooling the connection? I'm
> using Record Level Access on an AS400 DB2 database and I would much
> rather keep the logic in the bean than use the servlet to manage the
> connections.
>
>
> Thanks,
>
> Ben Dudley
>
This is *defiitely* an issue, and not just for database connections.
The key problem is that there is no "application start" and "application
end" notifications available in the servlet API spec (which would make
them available to both servlets and JSP pages). The issue has been
raised repeatedly in the expert group reviews of the servlet API, but
apparently there was not enough time to create, review, and approve such
a mechanism in time for the 2.2 API spec. Hopefully, we will see such a
mechanism formalized in a subsequent version of the servlet API.
In the mean time, I deal with this issue by making an assumption that is
true in the servlet engines I use, but is *definitely* not something you
can count on universally. I create my application-scope objects,
including database connections, in the init() method of a servlet that
is started up when the engine is started, and I gracefully shut them
down in the destroy() method of that same servlet. This works as long
as the servlet engine never decides to throw out my startup servlet
because nobody is accessing it, and also can have race condition issues
if you shut down while the app is in active use. But it's the best
idea I could come up with. I'd welcome any creative alternative
suggestions.
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html