dev@glassfish.java.net

addServlet question (glassfish v3)

From: Reik Schatz <reik.schatz_at_bwin.org>
Date: Mon, 15 Jun 2009 17:27:40 +0200

I am using the servletContext.addServlet method that was added in
Servlet 3.0 to dynamically add a new servlet. I wrote a
ServletContextListener and in the contextInitialized method, I
instantiate, initialize and add the Servlet. I expected that Glassfish
would use this instance when serving requests mapped to the servlet. But
this is not the case. Glassfish will create another instance instead. It
looks like it does that when I request the URL path and a Thread is
picked from the ThreadPool to handle the request. This is a bit
unfortunate since the new instance lacks my manual initialization.

Why does Glassfish instantiate another object when I call
servletContext.addServlet(String, Servlet) with a pre-intantiated Servlet?
/Reik