As we all know that Servlets come in the shape of Java objects hence there are plenty of variations as far as loading and unloading of them is concerned. The time when a server decides to load a specific Servlet, standard java class loading techniques are made use of to come up with a class instance. Making use of the same allows the Servlets to be loaded from any part of the network.
The server uses the init method of the Servlets to load the same. Prior to the client requests are taken care of, the initialization progression gets over and even before the Servlet is shattered.
Here is a simple and brief explanation on the process
Step1: Server is loaded and the Servlet is initiated.
Step2: There will be either no requests or quite a number of requests that the Servlet will be taking care of.
Step3: Servlet is removed by the Server. In some cases this step is performed only after the server gets shut down.

The real loading and implementation of the Servlets is clear-cut enough--when a client association is established and the Servlet is not in memory, it is loaded. However, a Servlet can be loaded if it has not yet been tackled with. A servlet can be loaded moreover at start of the server or vigorously when it is contacted.
Refer to the below for the signature of the method adopted to load and unload the Servlet.
public void init(ServletConfig config) throws ServletException public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException public void destroy()
The Servlet persists in the server, and is not reinitialized for each request. The life cycle of a Servlet is:
init()
* process individual requests
* if persistence is necessary, handle processed information
* destroy()
*
* @see javax.servlet.GenericServlet#init()
*/
public void init() {
xqueryMap = new HashMap();
indentationProperty = new Properties();
indentationProperty.setProperty("indent", "yes");
try {
dataSource = new DDXQDataSource(new
FileInputStream(XQueryServlet.CONFIG_FILE));
connection = dataSource.getConnection();
}
catch (Exception exception) {
System.out.println("Could not initialize DataDirect " +
"XQuery due to an Exeption:");
exception.printStackTrace();
}
/**
In order to determine which Servlets are loaded at the start of the server, the java web server consists of the administration section where all this details are captured. This permits the Servlets to be prepared in memory for the first client request to come in.
“Servlets that are expected to be most commonly and frequently used are loaded or installed at the start of the server”.
The response time for all the requests at the time when the Servlet is loaded at the start of the server is kept to a minimum. This reduces the wait time for the Servlet to be loaded.
Another explanation how the Servlet is loaded can be seen from the below figure.

There can be situations when the unloading of a Servlet takes place just after the completion of the client requests and not like the usual method of doing the same which is after shut down of the server.
At the time of the request handing out phase, there can be numerous threads administering the service () method of a Servlet instance. The Servlet container can transmit several synchronized requests via the service method of the Servlet. Hence it is up to the developer to appropriately grip the concurrency.
Making use SingleThreadModal and defining doGet, doPost or service methods with corresponding keywords is not appreciated due to performance factors.
.jpg)







See the prices for this post in Mr.Bool Credits System below: