• Post Reply Bookmark Topic Watch Topic
  • New Topic

init method

 
Mathews P Srampikal
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many time the init method will be executed.example usr1 login and invoked servelet1.later usr2 login and same servlet1 invoked.....In this case how many time the init method will be executed.....1 or 2.....I mean the same servlet instance will be servicing both the client....in that case it will be only once the init method will be executed.please give explain.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here I got some explanations from the "SCWCD Study Kit" of Hanumant... It says "It does not make sense to initialize an object repeatedly". So it will initialize only one time, regardless of how many users access that servlet... Hope this helps you...
This process of initializing a servlet using the initialization parameters from the
ServletConfig object is quite important in order to ensure the reusability of a
servlet. For example, if we wanted to create a database connection in the servlet we
would not want to hard-code the username/password and the database URL in the
servlet. The init() method allows us to specify them in the deployment descriptor.
The values in the deployment descriptor can be changed as needed without affecting
the servlet code. When the servlet initializes, it can read the values in its init()
method and make the connection.
It does not make sense to initialize an object repeatedly; therefore, the framework
guarantees that the servlet container will call the init() method once and only once
on a servlet instance.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The init method will be executed only once. This method will have to complete before the container can forward request to the servlet instance.
 
Mathews P Srampikal
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!