How to create Servlet Instance

Servlet Instance Creation:

Following ways we can create instance of a servlet:
  • By default servlet instance will be created when first client will send the request to the servlet.
  • Only one instance will be created for one servlet and will be used to process all the request by using multiple thread.
  • If you want to create the instance while starting the server or container then you can use the follwoing:
  1.  In Web.xml

// where I is int type value and it should not be negative.

 2.In Annotation 
  @WebServlet(....,loadOnStartup =I)