Why my servlet always be loaded for three times?

D

Duncan

my web.xml like below

<servlet>
<servlet-name>TimerAutoRecharge</servlet-name>
<servlet-class>com.unify.voip.control.TimerAutoRecharge</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>AppHandler_system</servlet-name>
<servlet-class>com.unify.voip.control.AppHandler</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>ApplRequestProcessor</servlet-name>
<servlet-class>com.unify.voip.control.ApplRequestProcessor</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>



<servlet-mapping>
<servlet-name>TimerAutoRecharge</servlet-name>
<url-pattern>/TimerAutoRecharge</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AppHandler_system</servlet-name>
<url-pattern>/AppHandler_system</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ApplRequestProcessor</servlet-name>
<url-pattern>/ClientProcessor</url-pattern>
</servlet-mapping>

Why all my three servlets are always being loaded for three times when
tomcat server startup?

Don't know why?
 
J

John C. Bollinger

Duncan said:
my web.xml like below

<servlet>
<servlet-name>TimerAutoRecharge</servlet-name>
<servlet-class>com.unify.voip.control.TimerAutoRecharge</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>AppHandler_system</servlet-name>
<servlet-class>com.unify.voip.control.AppHandler</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>ApplRequestProcessor</servlet-name>
<servlet-class>com.unify.voip.control.ApplRequestProcessor</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>



<servlet-mapping>
<servlet-name>TimerAutoRecharge</servlet-name>
<url-pattern>/TimerAutoRecharge</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AppHandler_system</servlet-name>
<url-pattern>/AppHandler_system</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ApplRequestProcessor</servlet-name>
<url-pattern>/ClientProcessor</url-pattern>
</servlet-mapping>

Why all my three servlets are always being loaded for three times when
tomcat server startup?

Define what you mean by all three servlets being loaded three times.
What is the evidence you have for this? Are you certain you have not
deployed multiple copies of your whole webapp?

No servlet container should ever maintain more than one live instance of
any servlet in any one webapp at any one time, but servlet containers
are free to at any time take one servlet instance out of service and
replace it with a different instance of the same servlet. Do note also
that there is a difference between the JVM loading and initializing the
servlet's class on the one hand, and the servlet container instantiating
the class and initializing the instance to prepare it for service. It
is the latter that load-on-startup should control (but, of course, that
requires on the former to have already happened).

Does the same thing happen if you remove the load-on-startup
specifications? Load-on-startup is rarely (if ever) necessary, except
as a crutch for poor webapp design, and I have yet to see an example
where it provided significant benefit (despite being unnecessary) to a
well-designed webapp. The typical uses of load-on-startup are served
better by suitable ServletContextListeners. Among other things,
ServletContextListeners have the property that the servlet spec requires
that they remain loaded until shutdown of the servlet container --
unlike servlet instances, for which there is no such gurantee.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top