Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q6 from chap 5 of HSFJ

 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it was given
"ServletContextListener can be used to perform an action when the servlet context is about to be shut down."

But ContextDestroyed() method is called only after Context is destroyed... Am i correct???
 
Will Lee
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void contextDestroyed(ServletContextEvent sce)

Notification that the servlet context is about to be shut down. All servlets have been destroy()ed before any ServletContextListeners are notified of context destruction.

Therefore I guess this listener give you last chance to clean up the resource of this app., AFTER all servlets are gone. At this moment app (context) is still there.

Am I right? As a matter of fact I am really confused about the post-fix (-ed) and "about to be".
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, from method name it looks obvious as method gets called after context is destroyed.
But according to servlet specification, it will be called just before session is destopyed.
I am pasting the below lines, as it is from servlet specification about ServletContextListener life cylce methods(contextInitialized, contextDestroyed).

"The servlet context has just been created and is available to service its first request, or the servlet context is about to be shut down"

About contextDestroyed method from J2EE API..

"Notification that the servlet context is about to be shut down. All servlets and filters have been destroy()ed before any servletContextListeners are notified of context destruction."
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so contextDestroyed() is called when the context is about to destroy

how many questions we may expect from thread-safe servlets in 310-081 exam???
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
attributeAdded(),attributeRemoved(),attributeReplaced() are called after event happens..
but getValue()returns attribute that has been added removed or replaced..means old value....am i right??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic