• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

HFSJ 2 ed. Final mock exam 43 question

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What’s true about the lifecycle of a servlet? (Choose all that apply.)
A. The service() method is the first method invoked by the container when a new request is received.
B. The service() method is invoked by either doPost() or doGet() after they’ve completed a request.
C. Each time that doPost() is invoked, it runs in its own thread.
D. The destroy() method is invoked after every invocation of doGet() completes.
E. The container issues a separate thread for each client request.


In the book C and E are correct but I thick that A also can be correct. If for example would be used <load-on-startup>1</load-on-startup> element in DD. Then init() method would be called by container but not when the request is coming. As I understand init() would be called first if there would be first request of the servlet and there is no any additional pre-compile and loading on startup options.

Am I correct?
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kiril.

A. The service() method is the first method invoked by the container when a new request is received.


I think, it is wrong. If we don't use <load-on-startup> service() method is not the first method invoked by the container. If we use <load-on-startup> it is first method.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure.... but it may have to do with the word "New" ....it says a "when a New request comes in"......it may mean the first request that invokes the servlet for the first time, when the servlet is "new", init() is invoked..... but obviously with each subsequent request it should be service()
Some times the way they formulate the questions is quite confusing
I ticked C & E too
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think 'E' is the correct one.
Because service() method is not the first method invocked, the flow is class-load->constructor->init(). After this servlet is initialized then on each request separate thread is created and service method is called in that thread. This is my understanding on what i read till not in HFSJ.
And 'C' is also the choice in the sense that service() method internally calls doPost()/doGet(), but in case of HttpServlet. In the case of GenericServlet (not specific to http) I found 'E' the correct one.
(please correct me if i am wrong).
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic