Servlet Operating Cycle and Threading

Servlets typically have the operating cycle, as shown in Figure 26-5.

Figure 26-5. Operating cycle of a servlet


Servlet life cycle

The sequence of events in a servlet's lifetime is:

  1. The servlet container starts up, and at some point constructs an instance of the servlet and calls its init() method. The init() method is only called once. Not once per request, not once per session, but once at the beginning of the servlet's lifetime. The init() method is a good place to put code to open a database connection.

  2. Unlike, say, a GUI, there is no background thread always running code in the servlet. ...

Get Just Java™ 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.