1

This link says that earlier versions of Tomcat (before 7.0.54) "renews its threads" thru ThreadPoolExecutor.run().

Why doesn't the init() method of contained Servlets seem to get called again?

Community
  • 1
  • 1
damat-perdigannat
  • 4,800
  • 1
  • 14
  • 27

1 Answers1

3

A Servlet is initialized only once, either at web application startup or upon first use.

The same instance will then be used to serve all incoming requests, if necessary even multiple requests at the same time (unless you use the deprecated option to synchronize access, but even then there will be just a single instance, and a queue of requests for it).

Thilo
  • 241,635
  • 91
  • 474
  • 626
  • 1
    @b16db0 the threads are reinitialized, but the servlet instance is *cached* per application and reused on the threads instances. – Luiggi Mendoza Aug 19 '14 at 06:07
  • 1
    Servlets are not bound to individual request worker threads. They are shared among them. – Thilo Aug 19 '14 at 06:07
  • @Thilo so, there will be only one instance of Servlet no matter whether there are a lot of requests coming in? – damat-perdigannat Aug 19 '14 at 06:19
  • 1
    That's right. One instance per configured Servlet (you can configure the same class more than once, but you get once instance per configuration). – Thilo Aug 19 '14 at 06:21