Hi All,
I'm planning on implementing my own database connection pool for an
upcoming project and would like your feedback. I have done some
research on the subject, so I'm not coming into this out of thin air,
but this is the first time I'll be doing any development on servlets so
please be gentle. :-)
Lets take it for granted that the connection pooling HAS to be done
within my servlet(s). Also, lets assume that I only have the need to
connect to one single database. What I am proposing to do is as
follows...
- I derive an abstract class out of HttpServlet, called DbServlet.
- My DbServlet class has a static Database connection pool object,
implemented using a list or a stack. It also has a static integer
which tells me how many servlets are currently using my connection
pool. DbServlet also implements four methods called...
AttachPool().
GetConnection().
ReleaseConnection().
ReleasePool().
- All my actual servlets derive from DbServlet.
- All my actual servlets call AttachPool() during init(), and
ReleasePool() during destroy().
- AttachPool() is implemented as follows...
If this is the first servlet that is attaching to the pool,
set up the pool of connections.
Increment the count of connected servlets.
- GetConnection() is implemented as follows...
If there are connections available, put it on the list of
in-use connections and return a reference to the caller.
If there are'nt any connections available return an error
message to the caller.
- ReleaseConnection() is implemented as follows...
Take the connection off the list of in-use connections and
put it back on the list of available connections.
- ReleasePool() is implemented as follows...
Decrement the count of servlets attached to the pool.
If the count has gone to zero, close all connections, taking
care to clean up after any in-use connections.
Thats it. Obviously, I'll make all the methods thread-safe. Any
thoughts? Please reply to the list, or to [EMAIL PROTECTED]
TIA.
Schubert Fernandes.
__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html