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