On 5/5/99 at 12:00 AM, Hans Bergsten <[EMAIL PROTECTED]> wrote:
> Manu Tayal wrote:
> >
> > Hi,
> > I have downloaded a the connection pool source code and I was trying to
> > run an example servlet given along with it. The example servlet is executing
> > perfectly. But the problem is that I have specified the maximum number of
> > connections as 3. Now the servlet is establishing the connection to the
> > database only thrice. The next time I try to run the servlet, it says
> > connection failed. I cannot figure out the problem. Or is it the way the
> > connection pool functions?
> >
> > Any help is appreciated.
>
> You don't say which of the many connection pool implementations available
> on the net that you're using, but a wild guess here is that you do not
> return the connection to the pool when you're done with it.
>
> All pools are intended to be used the same way:
>
> 1) You get a connection from the pool when you need it, typically
> in doGet/doPost,
> 2) You use it for a short time, typically just within the same
> method as where you got it,
> 3) You return it to the pool when you're done, typically just before
> returning from doGet/doPost.
It may not be clear to some people especially newer to Java. For this to work
correctly, returning the connection to the pool _must_ be in a finally clause.
It is imperative that under all circumstances the connection be return to the
pool otherwise -- well you end up where you are now.
Example:
...
Connection connection = null;
try
{
ConnectionPool.getConnection();
// Use the connection
}
finally
{
if ( connection != null ) ConnectionPool.returnConnection( connection );
}
In this way, no matter what happens the connection, if succesfully retrieved,
will always be returned to the pool.
...Duane
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ClueIn - The Internet's FREE Community Service.
Go to http://www.cluein.com and experience the most dynamic way to communicate with
groups of people! You are limited only by your imagination. This service is yours to
use free. Clue in now.
___________________________________________________________________________
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