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

is Action Servlet is designed as a Singleton class ?why?

 
Shiva Shankar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please answer this very urgent.

is Action Servlet is designed as a Singleton class ?if so why?

Thanks in advance.......
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the ActionServlet class is a singleton in the sense that there's only one per JVM. Why? Because the J2EE specification mandates that every servlet needs to work this way. It's a question of efficiency and memory conservancy. why have dozens or hundreds of instances of the same class in memory that all do the same thing? Because of this, all servlets must be coded as "thread-safe".

In a Struts application, not only is the ActionServlet a singleton, but also all your Action classes as well. You must code these classes as thread-safe also.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic