Hello all,
I've been trying out DB connection pooling and
encountered a really weird behavior.

This is what I wanted to do.  The information about db
connection is stored in web.xml, ie. db url, user
name, password, driver class.  I want to read those
settings in the EntryServlet which I mapped to the
root.  I am instantiating the connection pool class in
the init method of EntryServlet and put it in the
ServletContext so that other servlet can get it and
use it for their DAOs.  Then inside the doGet, I get
the requestedURI and send the page.

When I do that, it's all ok until I try to make the
conection pool class, then the requestedURI gets
printed like a million times * 100 (which I told it to
do for debug purpose but only ONCE) on the tomcat
console as if it is in infinite loop, then when it
finally stops I get the error.  Tell me what I am
doing wrong.

The errors I am getting are...
<Exception>
javax.servlet.ServletException: Servlet execution
threw an exception
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
and so on,
<root cause>
java.lang.StackOverflowError
        at
org.apache.catalina.connector.RequestFacade.removeAttribute(RequestFacade.java:221)
        at
org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:233)
        at
org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:233)
the above line is repeated close to a thousand times.
then, the following msg.at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:676)
        at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:431)
        at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:355)
        at common.EntryServlet.doGet(EntryServlet.java:65)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
        at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:431)
        at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:355)
        at common.EntryServlet.doGet(EntryServlet.java:65)
The above like gets repeated about the same time, I
don't know why.


This is my EntryServlet.(I am omitting import
statements to save space)

public class EntryServlet extends HttpServlet
{
    public void init() throws ServletException
    {
                ServletContext context = getServletContext();
                System.out.println("testing if there is already
dbPool in the context...");
                ConnectionPool dbPool =
(ConnectionPool)context.getAttribute("dbPool");
                // only if it hasn't been already instantiated
                if(dbPool == null)
                {
                        System.out.println("went inside the loop to
construct dbPool..");
                        // omitted, getting parameters from ServletContext
                        // instantiate ConnectionPool
                        try
                        {
                                System.out.println("got all parameters, making
dbPool..");
                                dbPool = new ConnectionPool(dbDriverClass, dbUrl,
dbUser, dbPassword, initConnections, maxConnections,
waitIfBusy);
                        }
                        catch(Exception e)
                        {
                                // I don't know what to do if that fails
                        }
                        System.out.println("made it, putting it in the
context");
                        context.setAttribute("dbPool", dbPool);
                }
        }

    public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException
    {
                String address = request.getRequestURI();
                System.out.println("requested address is" +
address);
                RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(address);
                dispatcher.forward(request, response);
    }

    public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException
    {
        doGet(request, response);
    }
}

This is part of my web.xml about mapping the
EntryServlet.

    <servlet-mapping>
        <servlet-name>entry</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>


And finally, my ConnectionPool implements Runnable and
I modifed only
a little from Marty Hall's example ConnectionPool
class.  I can't post it since it will make my msg too
long to be posted.


http://messenger.yahoo.com.au - Yahoo! Messenger
- A great way to communicate long-distance for FREE!

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to