This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes is Action Servlet is designed as a Singleton class ?why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "is Action Servlet is designed as a Singleton class ?why?" Watch "is Action Servlet is designed as a Singleton class ?why?" New topic
Author

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

Shiva Shankar
Ranch Hand

Joined: Dec 07, 2006
Posts: 31
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

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is Action Servlet is designed as a Singleton class ?why?