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

image

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.