Re: Best practice for initializing JDBC connection in Servlets.
From: Kevin McMurtrie (mcmurtri_at_dslextreme.com)
Date: 06/19/04
- Next message: Daniel Sjöblom: "Re: Iterator-Related Java Design Problem"
- Previous message: mromarkhan_at_rogers.com: "Re: Converting double to string in 7e100 format"
- In reply to: Alex Polite: "Best practice for initializing JDBC connection in Servlets."
- Next in thread: Roedy Green: "Re: Best practice for initializing JDBC connection in Servlets."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 19 Jun 2004 14:59:05 -0700
In article <20040619213437.GA2767@matijek.plusseven.com>,
Alex Polite <m4@polite.se> wrote:
> I'm starting out with servlets.
>
> I'm wondering about best practices for initializing JDBC
> connections. I've tried doing it in the servlet constructor and in
> doGet. Intuitively the constructor feels like the right place, but I
> wonder if there could be negative consequences when multiple clients
> access the servlet simultaneously? Or maybe I should do it in the init
> method?
>
> Any recommended reading available online?
> alex
For a very simple and low traffic service, it may be acceptable to
initialize the JDBC driver in init() and manage connections in doGet().
For best performance you should manage the JDBC connections outside the
servlet. A JDBC pool can cache connections during frequent use to
eliminate the overhead of establishing and destroying connections.
Often there's one pre-loading Servlet that does nothing except
initialize the application context, like the JDBC pooling.
Eventually you'll want to move all JDBC code out of the servlets. The
software will be easier to scale if the servlets only have to deal the
interface between an HTTP client and the server's data, not management
of the data too.
- Next message: Daniel Sjöblom: "Re: Iterator-Related Java Design Problem"
- Previous message: mromarkhan_at_rogers.com: "Re: Converting double to string in 7e100 format"
- In reply to: Alex Polite: "Best practice for initializing JDBC connection in Servlets."
- Next in thread: Roedy Green: "Re: Best practice for initializing JDBC connection in Servlets."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|